@dexto/tools-filesystem 1.5.7 → 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.
- package/dist/directory-approval.cjs +94 -0
- package/dist/directory-approval.d.cts +22 -0
- package/dist/directory-approval.d.ts +20 -0
- package/dist/directory-approval.d.ts.map +1 -0
- package/dist/directory-approval.integration.test.cjs +303 -269
- package/dist/directory-approval.integration.test.d.ts +14 -2
- package/dist/directory-approval.integration.test.d.ts.map +1 -0
- package/dist/directory-approval.integration.test.js +309 -270
- package/dist/directory-approval.js +59 -0
- package/dist/edit-file-tool.cjs +57 -90
- package/dist/edit-file-tool.d.cts +20 -3
- package/dist/edit-file-tool.d.ts +22 -9
- package/dist/edit-file-tool.d.ts.map +1 -0
- package/dist/edit-file-tool.js +53 -76
- package/dist/edit-file-tool.test.cjs +66 -29
- package/dist/edit-file-tool.test.d.ts +7 -2
- package/dist/edit-file-tool.test.d.ts.map +1 -0
- package/dist/edit-file-tool.test.js +66 -29
- package/dist/error-codes.d.ts +2 -3
- package/dist/error-codes.d.ts.map +1 -0
- package/dist/errors.d.ts +4 -7
- package/dist/errors.d.ts.map +1 -0
- package/dist/file-tool-types.d.cts +7 -35
- package/dist/file-tool-types.d.ts +8 -40
- package/dist/file-tool-types.d.ts.map +1 -0
- package/dist/filesystem-service.cjs +18 -1
- package/dist/filesystem-service.d.cts +11 -6
- package/dist/filesystem-service.d.ts +14 -12
- package/dist/filesystem-service.d.ts.map +1 -0
- package/dist/filesystem-service.js +18 -1
- package/dist/filesystem-service.test.cjs +10 -2
- package/dist/filesystem-service.test.d.ts +7 -2
- package/dist/filesystem-service.test.d.ts.map +1 -0
- package/dist/filesystem-service.test.js +10 -2
- package/dist/glob-files-tool.cjs +22 -47
- package/dist/glob-files-tool.d.cts +17 -3
- package/dist/glob-files-tool.d.ts +19 -9
- package/dist/glob-files-tool.d.ts.map +1 -0
- package/dist/glob-files-tool.js +23 -48
- package/dist/grep-content-tool.cjs +29 -46
- package/dist/grep-content-tool.d.cts +26 -3
- package/dist/grep-content-tool.d.ts +28 -9
- package/dist/grep-content-tool.d.ts.map +1 -0
- package/dist/grep-content-tool.js +30 -47
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +10 -5
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -2
- package/dist/path-validator.d.cts +2 -2
- package/dist/path-validator.d.ts +6 -9
- package/dist/path-validator.d.ts.map +1 -0
- package/dist/path-validator.test.d.ts +7 -2
- package/dist/path-validator.test.d.ts.map +1 -0
- package/dist/read-file-tool.cjs +21 -60
- package/dist/read-file-tool.d.cts +17 -3
- package/dist/read-file-tool.d.ts +19 -9
- package/dist/read-file-tool.d.ts.map +1 -0
- package/dist/read-file-tool.js +22 -51
- package/dist/tool-factory-config.cjs +61 -0
- package/dist/{tool-provider.d.ts → tool-factory-config.d.cts} +9 -23
- package/dist/{tool-provider.d.cts → tool-factory-config.d.ts} +13 -30
- package/dist/tool-factory-config.d.ts.map +1 -0
- package/dist/tool-factory-config.js +36 -0
- package/dist/tool-factory.cjs +102 -0
- package/dist/tool-factory.d.cts +7 -0
- package/dist/tool-factory.d.ts +4 -0
- package/dist/tool-factory.d.ts.map +1 -0
- package/dist/tool-factory.js +81 -0
- package/dist/types.d.ts +17 -18
- package/dist/types.d.ts.map +1 -0
- package/dist/write-file-tool.cjs +45 -73
- package/dist/write-file-tool.d.cts +20 -3
- package/dist/write-file-tool.d.ts +22 -9
- package/dist/write-file-tool.d.ts.map +1 -0
- package/dist/write-file-tool.js +46 -68
- package/dist/write-file-tool.test.cjs +76 -32
- package/dist/write-file-tool.test.d.ts +7 -2
- package/dist/write-file-tool.test.d.ts.map +1 -0
- package/dist/write-file-tool.test.js +76 -32
- package/package.json +4 -3
- package/dist/tool-provider.cjs +0 -123
- 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"}
|