@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
@@ -0,0 +1,94 @@
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 __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var directory_approval_exports = {};
30
+ __export(directory_approval_exports, {
31
+ createDirectoryAccessApprovalHandlers: () => createDirectoryAccessApprovalHandlers,
32
+ resolveFilePath: () => resolveFilePath
33
+ });
34
+ module.exports = __toCommonJS(directory_approval_exports);
35
+ var path = __toESM(require("node:path"), 1);
36
+ var import_core = require("@dexto/core");
37
+ function resolveFilePath(workingDirectory, filePath) {
38
+ const resolvedPath = path.isAbsolute(filePath) ? path.resolve(filePath) : path.resolve(workingDirectory, filePath);
39
+ return { path: resolvedPath, parentDir: path.dirname(resolvedPath) };
40
+ }
41
+ function createDirectoryAccessApprovalHandlers(options) {
42
+ return {
43
+ async getApprovalOverride(input, context) {
44
+ const resolvedFileSystemService = await options.getFileSystemService(context);
45
+ const paths = options.resolvePaths(input, resolvedFileSystemService);
46
+ const isAllowed = await resolvedFileSystemService.isPathWithinConfigAllowed(paths.path);
47
+ if (isAllowed) {
48
+ return null;
49
+ }
50
+ const approvalManager = context.services?.approval;
51
+ if (!approvalManager) {
52
+ throw import_core.ToolError.configInvalid(
53
+ `${options.toolName} requires ToolExecutionContext.services.approval`
54
+ );
55
+ }
56
+ if (approvalManager.isDirectorySessionApproved(paths.path)) {
57
+ return null;
58
+ }
59
+ return {
60
+ type: import_core.ApprovalType.DIRECTORY_ACCESS,
61
+ metadata: {
62
+ path: paths.path,
63
+ parentDir: paths.parentDir,
64
+ operation: options.operation,
65
+ toolName: options.toolName
66
+ }
67
+ };
68
+ },
69
+ onApprovalGranted(response, context, approvalRequest) {
70
+ if (approvalRequest.type !== import_core.ApprovalType.DIRECTORY_ACCESS) {
71
+ return;
72
+ }
73
+ const metadata = approvalRequest.metadata;
74
+ const parentDir = typeof metadata?.parentDir === "string" ? metadata.parentDir : null;
75
+ if (!parentDir) {
76
+ return;
77
+ }
78
+ const data = response.data;
79
+ const rememberDirectory = data?.rememberDirectory ?? false;
80
+ const approvalManager = context.services?.approval;
81
+ if (!approvalManager) {
82
+ throw import_core.ToolError.configInvalid(
83
+ `${options.toolName} requires ToolExecutionContext.services.approval`
84
+ );
85
+ }
86
+ approvalManager.addApprovedDirectory(parentDir, rememberDirectory ? "session" : "once");
87
+ }
88
+ };
89
+ }
90
+ // Annotate the CommonJS export names for ESM import in node:
91
+ 0 && (module.exports = {
92
+ createDirectoryAccessApprovalHandlers,
93
+ resolveFilePath
94
+ });
@@ -0,0 +1,22 @@
1
+ import { ToolExecutionContext, ApprovalRequestDetails, ApprovalResponse } from '@dexto/core';
2
+ import { FileSystemService } from './filesystem-service.cjs';
3
+ import { FileSystemServiceGetter } from './file-tool-types.cjs';
4
+ import './types.cjs';
5
+
6
+ type DirectoryApprovalOperation = 'read' | 'write' | 'edit';
7
+ type DirectoryApprovalPaths = {
8
+ path: string;
9
+ parentDir: string;
10
+ };
11
+ declare function resolveFilePath(workingDirectory: string, filePath: string): DirectoryApprovalPaths;
12
+ declare function createDirectoryAccessApprovalHandlers<TInput>(options: {
13
+ toolName: string;
14
+ operation: DirectoryApprovalOperation;
15
+ getFileSystemService: FileSystemServiceGetter;
16
+ resolvePaths: (input: TInput, fileSystemService: FileSystemService) => DirectoryApprovalPaths;
17
+ }): {
18
+ getApprovalOverride: (input: TInput, context: ToolExecutionContext) => Promise<ApprovalRequestDetails | null>;
19
+ onApprovalGranted: (response: ApprovalResponse, context: ToolExecutionContext, approvalRequest: ApprovalRequestDetails) => void;
20
+ };
21
+
22
+ export { createDirectoryAccessApprovalHandlers, resolveFilePath };
@@ -0,0 +1,20 @@
1
+ import type { ApprovalRequestDetails, ApprovalResponse, ToolExecutionContext } from '@dexto/core';
2
+ import type { FileSystemService } from './filesystem-service.js';
3
+ import type { FileSystemServiceGetter } from './file-tool-types.js';
4
+ type DirectoryApprovalOperation = 'read' | 'write' | 'edit';
5
+ type DirectoryApprovalPaths = {
6
+ path: string;
7
+ parentDir: string;
8
+ };
9
+ export declare function resolveFilePath(workingDirectory: string, filePath: string): DirectoryApprovalPaths;
10
+ export declare function createDirectoryAccessApprovalHandlers<TInput>(options: {
11
+ toolName: string;
12
+ operation: DirectoryApprovalOperation;
13
+ getFileSystemService: FileSystemServiceGetter;
14
+ resolvePaths: (input: TInput, fileSystemService: FileSystemService) => DirectoryApprovalPaths;
15
+ }): {
16
+ getApprovalOverride: (input: TInput, context: ToolExecutionContext) => Promise<ApprovalRequestDetails | null>;
17
+ onApprovalGranted: (response: ApprovalResponse, context: ToolExecutionContext, approvalRequest: ApprovalRequestDetails) => void;
18
+ };
19
+ export {};
20
+ //# sourceMappingURL=directory-approval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directory-approval.d.ts","sourceRoot":"","sources":["../src/directory-approval.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAClG,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAEpE,KAAK,0BAA0B,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AAE5D,KAAK,sBAAsB,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,wBAAgB,eAAe,CAC3B,gBAAgB,EAAE,MAAM,EACxB,QAAQ,EAAE,MAAM,GACjB,sBAAsB,CAKxB;AAED,wBAAgB,qCAAqC,CAAC,MAAM,EAAE,OAAO,EAAE;IACnE,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,0BAA0B,CAAC;IACtC,oBAAoB,EAAE,uBAAuB,CAAC;IAC9C,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,iBAAiB,KAAK,sBAAsB,CAAC;CACjG,GAAG;IACA,mBAAmB,EAAE,CACjB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,oBAAoB,KAC5B,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAAC;IAC5C,iBAAiB,EAAE,CACf,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,oBAAoB,EAC7B,eAAe,EAAE,sBAAsB,KACtC,IAAI,CAAC;CACb,CA+DA"}