@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
package/LICENSE ADDED
@@ -0,0 +1,44 @@
1
+ Elastic License 2.0 (ELv2)
2
+
3
+ **Acceptance**
4
+ By using the software, you agree to all of the terms and conditions below.
5
+
6
+ **Copyright License**
7
+ The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
8
+
9
+ **Limitations**
10
+ You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
11
+
12
+ You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
13
+
14
+ You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
15
+
16
+ **Patents**
17
+ The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
18
+
19
+ **Notices**
20
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
21
+
22
+ If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
23
+
24
+ **No Other Rights**
25
+ These terms do not imply any licenses other than those expressly granted in these terms.
26
+
27
+ **Termination**
28
+ If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
29
+
30
+ **No Liability**
31
+ As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
32
+
33
+ **Definitions**
34
+ The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
35
+
36
+ _you_ refers to the individual or entity agreeing to these terms.
37
+
38
+ _your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
39
+
40
+ _your licenses_ are all the licenses granted to you for the software under these terms.
41
+
42
+ _use_ means anything you do with the software requiring one of your licenses.
43
+
44
+ _trademark_ means trademarks, service marks, and similar rights.
@@ -0,0 +1,467 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var import_vitest = require("vitest");
25
+ var path = __toESM(require("node:path"), 1);
26
+ var fs = __toESM(require("node:fs/promises"), 1);
27
+ var os = __toESM(require("node:os"), 1);
28
+ var import_read_file_tool = require("./read-file-tool.js");
29
+ var import_write_file_tool = require("./write-file-tool.js");
30
+ var import_edit_file_tool = require("./edit-file-tool.js");
31
+ var import_filesystem_service = require("./filesystem-service.js");
32
+ var import_core = require("@dexto/core");
33
+ const createMockLogger = () => ({
34
+ debug: import_vitest.vi.fn(),
35
+ info: import_vitest.vi.fn(),
36
+ warn: import_vitest.vi.fn(),
37
+ error: import_vitest.vi.fn(),
38
+ createChild: import_vitest.vi.fn().mockReturnThis()
39
+ });
40
+ (0, import_vitest.describe)("Directory Approval Integration Tests", () => {
41
+ let mockLogger;
42
+ let tempDir;
43
+ let fileSystemService;
44
+ let directoryApproval;
45
+ let isSessionApprovedMock;
46
+ let addApprovedMock;
47
+ (0, import_vitest.beforeEach)(async () => {
48
+ mockLogger = createMockLogger();
49
+ const rawTempDir = await fs.mkdtemp(path.join(os.tmpdir(), "dexto-fs-test-"));
50
+ tempDir = await fs.realpath(rawTempDir);
51
+ fileSystemService = new import_filesystem_service.FileSystemService(
52
+ {
53
+ allowedPaths: [tempDir],
54
+ blockedPaths: [],
55
+ blockedExtensions: [],
56
+ maxFileSize: 10 * 1024 * 1024,
57
+ workingDirectory: tempDir,
58
+ enableBackups: false,
59
+ backupRetentionDays: 7
60
+ },
61
+ mockLogger
62
+ );
63
+ await fileSystemService.initialize();
64
+ isSessionApprovedMock = import_vitest.vi.fn().mockReturnValue(false);
65
+ addApprovedMock = import_vitest.vi.fn();
66
+ directoryApproval = {
67
+ isSessionApproved: isSessionApprovedMock,
68
+ addApproved: addApprovedMock
69
+ };
70
+ import_vitest.vi.clearAllMocks();
71
+ });
72
+ (0, import_vitest.afterEach)(async () => {
73
+ try {
74
+ await fs.rm(tempDir, { recursive: true, force: true });
75
+ } catch {
76
+ }
77
+ });
78
+ (0, import_vitest.describe)("Read File Tool", () => {
79
+ (0, import_vitest.describe)("getApprovalOverride", () => {
80
+ (0, import_vitest.it)("should return null for paths within working directory (no prompt needed)", async () => {
81
+ const tool = (0, import_read_file_tool.createReadFileTool)({
82
+ fileSystemService,
83
+ directoryApproval
84
+ });
85
+ const testFile = path.join(tempDir, "test.txt");
86
+ await fs.writeFile(testFile, "test content");
87
+ const override = tool.getApprovalOverride?.({ file_path: testFile });
88
+ (0, import_vitest.expect)(override).toBeNull();
89
+ });
90
+ (0, import_vitest.it)("should return directory access approval for external paths", async () => {
91
+ const tool = (0, import_read_file_tool.createReadFileTool)({
92
+ fileSystemService,
93
+ directoryApproval
94
+ });
95
+ const externalPath = "/external/project/file.ts";
96
+ const override = tool.getApprovalOverride?.({ file_path: externalPath });
97
+ (0, import_vitest.expect)(override).not.toBeNull();
98
+ (0, import_vitest.expect)(override?.type).toBe(import_core.ApprovalType.DIRECTORY_ACCESS);
99
+ const metadata = override?.metadata;
100
+ (0, import_vitest.expect)(metadata?.path).toBe(path.resolve(externalPath));
101
+ (0, import_vitest.expect)(metadata?.parentDir).toBe(path.dirname(path.resolve(externalPath)));
102
+ (0, import_vitest.expect)(metadata?.operation).toBe("read");
103
+ (0, import_vitest.expect)(metadata?.toolName).toBe("read_file");
104
+ });
105
+ (0, import_vitest.it)("should return null when external path is session-approved", async () => {
106
+ isSessionApprovedMock.mockReturnValue(true);
107
+ const tool = (0, import_read_file_tool.createReadFileTool)({
108
+ fileSystemService,
109
+ directoryApproval
110
+ });
111
+ const externalPath = "/external/project/file.ts";
112
+ const override = tool.getApprovalOverride?.({ file_path: externalPath });
113
+ (0, import_vitest.expect)(override).toBeNull();
114
+ (0, import_vitest.expect)(isSessionApprovedMock).toHaveBeenCalledWith(externalPath);
115
+ });
116
+ (0, import_vitest.it)("should return null when file_path is missing", async () => {
117
+ const tool = (0, import_read_file_tool.createReadFileTool)({
118
+ fileSystemService,
119
+ directoryApproval
120
+ });
121
+ const override = tool.getApprovalOverride?.({});
122
+ (0, import_vitest.expect)(override).toBeNull();
123
+ });
124
+ });
125
+ (0, import_vitest.describe)("onApprovalGranted", () => {
126
+ (0, import_vitest.it)("should add directory as session-approved when rememberDirectory is true", async () => {
127
+ const tool = (0, import_read_file_tool.createReadFileTool)({
128
+ fileSystemService,
129
+ directoryApproval
130
+ });
131
+ const externalPath = "/external/project/file.ts";
132
+ tool.getApprovalOverride?.({ file_path: externalPath });
133
+ tool.onApprovalGranted?.({
134
+ approvalId: "test-approval",
135
+ status: import_core.ApprovalStatus.APPROVED,
136
+ data: { rememberDirectory: true }
137
+ });
138
+ (0, import_vitest.expect)(addApprovedMock).toHaveBeenCalledWith(
139
+ path.dirname(path.resolve(externalPath)),
140
+ "session"
141
+ );
142
+ });
143
+ (0, import_vitest.it)("should add directory as once-approved when rememberDirectory is false", async () => {
144
+ const tool = (0, import_read_file_tool.createReadFileTool)({
145
+ fileSystemService,
146
+ directoryApproval
147
+ });
148
+ const externalPath = "/external/project/file.ts";
149
+ tool.getApprovalOverride?.({ file_path: externalPath });
150
+ tool.onApprovalGranted?.({
151
+ approvalId: "test-approval",
152
+ status: import_core.ApprovalStatus.APPROVED,
153
+ data: { rememberDirectory: false }
154
+ });
155
+ (0, import_vitest.expect)(addApprovedMock).toHaveBeenCalledWith(
156
+ path.dirname(path.resolve(externalPath)),
157
+ "once"
158
+ );
159
+ });
160
+ (0, import_vitest.it)("should default to once-approved when rememberDirectory is not specified", async () => {
161
+ const tool = (0, import_read_file_tool.createReadFileTool)({
162
+ fileSystemService,
163
+ directoryApproval
164
+ });
165
+ const externalPath = "/external/project/file.ts";
166
+ tool.getApprovalOverride?.({ file_path: externalPath });
167
+ tool.onApprovalGranted?.({
168
+ approvalId: "test-approval",
169
+ status: import_core.ApprovalStatus.APPROVED,
170
+ data: {}
171
+ });
172
+ (0, import_vitest.expect)(addApprovedMock).toHaveBeenCalledWith(
173
+ path.dirname(path.resolve(externalPath)),
174
+ "once"
175
+ );
176
+ });
177
+ (0, import_vitest.it)("should not call addApproved when directoryApproval is not provided", async () => {
178
+ const tool = (0, import_read_file_tool.createReadFileTool)({
179
+ fileSystemService,
180
+ directoryApproval: void 0
181
+ });
182
+ const externalPath = "/external/project/file.ts";
183
+ tool.getApprovalOverride?.({ file_path: externalPath });
184
+ tool.onApprovalGranted?.({
185
+ approvalId: "test-approval",
186
+ status: import_core.ApprovalStatus.APPROVED,
187
+ data: { rememberDirectory: true }
188
+ });
189
+ (0, import_vitest.expect)(addApprovedMock).not.toHaveBeenCalled();
190
+ });
191
+ });
192
+ (0, import_vitest.describe)("execute", () => {
193
+ (0, import_vitest.it)("should read file contents within working directory", async () => {
194
+ const tool = (0, import_read_file_tool.createReadFileTool)({
195
+ fileSystemService,
196
+ directoryApproval
197
+ });
198
+ const testFile = path.join(tempDir, "readable.txt");
199
+ await fs.writeFile(testFile, "Hello, world!\nLine 2");
200
+ const result = await tool.execute({ file_path: testFile }, {});
201
+ (0, import_vitest.expect)(result.content).toBe("Hello, world!\nLine 2");
202
+ (0, import_vitest.expect)(result.lines).toBe(2);
203
+ });
204
+ });
205
+ });
206
+ (0, import_vitest.describe)("Write File Tool", () => {
207
+ (0, import_vitest.describe)("getApprovalOverride", () => {
208
+ (0, import_vitest.it)("should return null for paths within working directory", async () => {
209
+ const tool = (0, import_write_file_tool.createWriteFileTool)({
210
+ fileSystemService,
211
+ directoryApproval
212
+ });
213
+ const testFile = path.join(tempDir, "new-file.txt");
214
+ const override = tool.getApprovalOverride?.({
215
+ file_path: testFile,
216
+ content: "test"
217
+ });
218
+ (0, import_vitest.expect)(override).toBeNull();
219
+ });
220
+ (0, import_vitest.it)("should return directory access approval for external paths", async () => {
221
+ const tool = (0, import_write_file_tool.createWriteFileTool)({
222
+ fileSystemService,
223
+ directoryApproval
224
+ });
225
+ const externalPath = "/external/project/new.ts";
226
+ const override = tool.getApprovalOverride?.({
227
+ file_path: externalPath,
228
+ content: "test"
229
+ });
230
+ (0, import_vitest.expect)(override).not.toBeNull();
231
+ (0, import_vitest.expect)(override?.type).toBe(import_core.ApprovalType.DIRECTORY_ACCESS);
232
+ const metadata = override?.metadata;
233
+ (0, import_vitest.expect)(metadata?.operation).toBe("write");
234
+ (0, import_vitest.expect)(metadata?.toolName).toBe("write_file");
235
+ });
236
+ (0, import_vitest.it)("should return null when external path is session-approved", async () => {
237
+ isSessionApprovedMock.mockReturnValue(true);
238
+ const tool = (0, import_write_file_tool.createWriteFileTool)({
239
+ fileSystemService,
240
+ directoryApproval
241
+ });
242
+ const externalPath = "/external/project/new.ts";
243
+ const override = tool.getApprovalOverride?.({
244
+ file_path: externalPath,
245
+ content: "test"
246
+ });
247
+ (0, import_vitest.expect)(override).toBeNull();
248
+ });
249
+ });
250
+ (0, import_vitest.describe)("onApprovalGranted", () => {
251
+ (0, import_vitest.it)("should add directory as session-approved when rememberDirectory is true", async () => {
252
+ const tool = (0, import_write_file_tool.createWriteFileTool)({
253
+ fileSystemService,
254
+ directoryApproval
255
+ });
256
+ const externalPath = "/external/project/new.ts";
257
+ tool.getApprovalOverride?.({ file_path: externalPath, content: "test" });
258
+ tool.onApprovalGranted?.({
259
+ approvalId: "test-approval",
260
+ status: import_core.ApprovalStatus.APPROVED,
261
+ data: { rememberDirectory: true }
262
+ });
263
+ (0, import_vitest.expect)(addApprovedMock).toHaveBeenCalledWith(
264
+ path.dirname(path.resolve(externalPath)),
265
+ "session"
266
+ );
267
+ });
268
+ });
269
+ });
270
+ (0, import_vitest.describe)("Edit File Tool", () => {
271
+ (0, import_vitest.describe)("getApprovalOverride", () => {
272
+ (0, import_vitest.it)("should return null for paths within working directory", async () => {
273
+ const tool = (0, import_edit_file_tool.createEditFileTool)({
274
+ fileSystemService,
275
+ directoryApproval
276
+ });
277
+ const testFile = path.join(tempDir, "existing.txt");
278
+ const override = tool.getApprovalOverride?.({
279
+ file_path: testFile,
280
+ old_string: "old",
281
+ new_string: "new"
282
+ });
283
+ (0, import_vitest.expect)(override).toBeNull();
284
+ });
285
+ (0, import_vitest.it)("should return directory access approval for external paths", async () => {
286
+ const tool = (0, import_edit_file_tool.createEditFileTool)({
287
+ fileSystemService,
288
+ directoryApproval
289
+ });
290
+ const externalPath = "/external/project/existing.ts";
291
+ const override = tool.getApprovalOverride?.({
292
+ file_path: externalPath,
293
+ old_string: "old",
294
+ new_string: "new"
295
+ });
296
+ (0, import_vitest.expect)(override).not.toBeNull();
297
+ (0, import_vitest.expect)(override?.type).toBe(import_core.ApprovalType.DIRECTORY_ACCESS);
298
+ const metadata = override?.metadata;
299
+ (0, import_vitest.expect)(metadata?.operation).toBe("edit");
300
+ (0, import_vitest.expect)(metadata?.toolName).toBe("edit_file");
301
+ });
302
+ (0, import_vitest.it)("should return null when external path is session-approved", async () => {
303
+ isSessionApprovedMock.mockReturnValue(true);
304
+ const tool = (0, import_edit_file_tool.createEditFileTool)({
305
+ fileSystemService,
306
+ directoryApproval
307
+ });
308
+ const externalPath = "/external/project/existing.ts";
309
+ const override = tool.getApprovalOverride?.({
310
+ file_path: externalPath,
311
+ old_string: "old",
312
+ new_string: "new"
313
+ });
314
+ (0, import_vitest.expect)(override).toBeNull();
315
+ });
316
+ });
317
+ });
318
+ (0, import_vitest.describe)("Session vs Once Approval Scenarios", () => {
319
+ (0, import_vitest.it)("should not prompt for subsequent requests after session approval", async () => {
320
+ const tool = (0, import_read_file_tool.createReadFileTool)({
321
+ fileSystemService,
322
+ directoryApproval
323
+ });
324
+ const externalPath1 = "/external/project/file1.ts";
325
+ const externalPath2 = "/external/project/file2.ts";
326
+ let override = tool.getApprovalOverride?.({ file_path: externalPath1 });
327
+ (0, import_vitest.expect)(override).not.toBeNull();
328
+ tool.onApprovalGranted?.({
329
+ approvalId: "approval-1",
330
+ status: import_core.ApprovalStatus.APPROVED,
331
+ data: { rememberDirectory: true }
332
+ });
333
+ (0, import_vitest.expect)(addApprovedMock).toHaveBeenCalledWith(
334
+ path.dirname(path.resolve(externalPath1)),
335
+ "session"
336
+ );
337
+ isSessionApprovedMock.mockReturnValue(true);
338
+ override = tool.getApprovalOverride?.({ file_path: externalPath2 });
339
+ (0, import_vitest.expect)(override).toBeNull();
340
+ });
341
+ (0, import_vitest.it)("should prompt for subsequent requests after once approval", async () => {
342
+ const tool = (0, import_read_file_tool.createReadFileTool)({
343
+ fileSystemService,
344
+ directoryApproval
345
+ });
346
+ const externalPath1 = "/external/project/file1.ts";
347
+ const externalPath2 = "/external/project/file2.ts";
348
+ let override = tool.getApprovalOverride?.({ file_path: externalPath1 });
349
+ (0, import_vitest.expect)(override).not.toBeNull();
350
+ tool.onApprovalGranted?.({
351
+ approvalId: "approval-1",
352
+ status: import_core.ApprovalStatus.APPROVED,
353
+ data: { rememberDirectory: false }
354
+ });
355
+ (0, import_vitest.expect)(addApprovedMock).toHaveBeenCalledWith(
356
+ path.dirname(path.resolve(externalPath1)),
357
+ "once"
358
+ );
359
+ isSessionApprovedMock.mockReturnValue(false);
360
+ override = tool.getApprovalOverride?.({ file_path: externalPath2 });
361
+ (0, import_vitest.expect)(override).not.toBeNull();
362
+ });
363
+ });
364
+ (0, import_vitest.describe)("Path Containment Scenarios", () => {
365
+ (0, import_vitest.it)("should cover child paths when parent directory is session-approved", async () => {
366
+ const tool = (0, import_read_file_tool.createReadFileTool)({
367
+ fileSystemService,
368
+ directoryApproval
369
+ });
370
+ isSessionApprovedMock.mockImplementation((filePath) => {
371
+ const normalizedPath = path.resolve(filePath);
372
+ const approvedDir = "/external/project";
373
+ return normalizedPath.startsWith(approvedDir + path.sep) || normalizedPath === approvedDir;
374
+ });
375
+ let override = tool.getApprovalOverride?.({ file_path: "/external/project/file.ts" });
376
+ (0, import_vitest.expect)(override).toBeNull();
377
+ override = tool.getApprovalOverride?.({
378
+ file_path: "/external/project/deep/nested/file.ts"
379
+ });
380
+ (0, import_vitest.expect)(override).toBeNull();
381
+ });
382
+ (0, import_vitest.it)("should NOT cover sibling directories", async () => {
383
+ const tool = (0, import_read_file_tool.createReadFileTool)({
384
+ fileSystemService,
385
+ directoryApproval
386
+ });
387
+ isSessionApprovedMock.mockImplementation((filePath) => {
388
+ const normalizedPath = path.resolve(filePath);
389
+ const approvedDir = "/external/sub";
390
+ return normalizedPath.startsWith(approvedDir + path.sep) || normalizedPath === approvedDir;
391
+ });
392
+ let override = tool.getApprovalOverride?.({ file_path: "/external/sub/file.ts" });
393
+ (0, import_vitest.expect)(override).toBeNull();
394
+ override = tool.getApprovalOverride?.({ file_path: "/external/other/file.ts" });
395
+ (0, import_vitest.expect)(override).not.toBeNull();
396
+ });
397
+ });
398
+ (0, import_vitest.describe)("Different External Directories Scenarios", () => {
399
+ (0, import_vitest.it)("should require separate approval for different external directories", async () => {
400
+ const tool = (0, import_read_file_tool.createReadFileTool)({
401
+ fileSystemService,
402
+ directoryApproval
403
+ });
404
+ const dir1Path = "/external/project1/file.ts";
405
+ const dir2Path = "/external/project2/file.ts";
406
+ const override1 = tool.getApprovalOverride?.({ file_path: dir1Path });
407
+ (0, import_vitest.expect)(override1).not.toBeNull();
408
+ const metadata1 = override1?.metadata;
409
+ (0, import_vitest.expect)(metadata1?.parentDir).toBe("/external/project1");
410
+ const override2 = tool.getApprovalOverride?.({ file_path: dir2Path });
411
+ (0, import_vitest.expect)(override2).not.toBeNull();
412
+ const metadata2 = override2?.metadata;
413
+ (0, import_vitest.expect)(metadata2?.parentDir).toBe("/external/project2");
414
+ });
415
+ });
416
+ (0, import_vitest.describe)("Mixed Operations Scenarios", () => {
417
+ (0, import_vitest.it)("should share directory approval across different file operations", async () => {
418
+ const readTool = (0, import_read_file_tool.createReadFileTool)({ fileSystemService, directoryApproval });
419
+ const writeTool = (0, import_write_file_tool.createWriteFileTool)({ fileSystemService, directoryApproval });
420
+ const editTool = (0, import_edit_file_tool.createEditFileTool)({ fileSystemService, directoryApproval });
421
+ const externalDir = "/external/project";
422
+ (0, import_vitest.expect)(
423
+ readTool.getApprovalOverride?.({ file_path: `${externalDir}/file1.ts` })
424
+ ).not.toBeNull();
425
+ (0, import_vitest.expect)(
426
+ writeTool.getApprovalOverride?.({
427
+ file_path: `${externalDir}/file2.ts`,
428
+ content: "test"
429
+ })
430
+ ).not.toBeNull();
431
+ (0, import_vitest.expect)(
432
+ editTool.getApprovalOverride?.({
433
+ file_path: `${externalDir}/file3.ts`,
434
+ old_string: "a",
435
+ new_string: "b"
436
+ })
437
+ ).not.toBeNull();
438
+ isSessionApprovedMock.mockReturnValue(true);
439
+ (0, import_vitest.expect)(
440
+ readTool.getApprovalOverride?.({ file_path: `${externalDir}/file1.ts` })
441
+ ).toBeNull();
442
+ (0, import_vitest.expect)(
443
+ writeTool.getApprovalOverride?.({
444
+ file_path: `${externalDir}/file2.ts`,
445
+ content: "test"
446
+ })
447
+ ).toBeNull();
448
+ (0, import_vitest.expect)(
449
+ editTool.getApprovalOverride?.({
450
+ file_path: `${externalDir}/file3.ts`,
451
+ old_string: "a",
452
+ new_string: "b"
453
+ })
454
+ ).toBeNull();
455
+ });
456
+ });
457
+ (0, import_vitest.describe)("Without Directory Approval Callbacks", () => {
458
+ (0, import_vitest.it)("should work without directory approval callbacks (all paths need normal tool confirmation)", async () => {
459
+ const tool = (0, import_read_file_tool.createReadFileTool)({
460
+ fileSystemService,
461
+ directoryApproval: void 0
462
+ });
463
+ const override = tool.getApprovalOverride?.({ file_path: "/external/project/file.ts" });
464
+ (0, import_vitest.expect)(override).not.toBeNull();
465
+ });
466
+ });
467
+ });
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,2 @@
1
+
2
+ export { }