@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 @@
|
|
|
1
|
+
{"version":3,"file":"read-file-tool.d.ts","sourceRoot":"","sources":["../src/read-file-tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAmB,IAAI,EAAwB,MAAM,aAAa,CAAC;AAC/E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAGpE,QAAA,MAAM,mBAAmB;;;;;;;;;;;;EAgBZ,CAAC;AAEd;;GAEG;AACH,wBAAgB,kBAAkB,CAC9B,oBAAoB,EAAE,uBAAuB,GAC9C,IAAI,CAAC,OAAO,mBAAmB,CAAC,CAqDlC"}
|
package/dist/read-file-tool.js
CHANGED
|
@@ -1,67 +1,38 @@
|
|
|
1
|
-
import * as path from "node:path";
|
|
2
1
|
import { z } from "zod";
|
|
3
|
-
import {
|
|
2
|
+
import { defineTool } from "@dexto/core";
|
|
3
|
+
import { createDirectoryAccessApprovalHandlers, resolveFilePath } from "./directory-approval.js";
|
|
4
4
|
const ReadFileInputSchema = z.object({
|
|
5
|
-
file_path: z.string().describe("Absolute path to the file to read"),
|
|
5
|
+
file_path: z.string().min(1).describe("Absolute path to the file to read"),
|
|
6
6
|
limit: z.number().int().positive().optional().describe("Maximum number of lines to read (optional)"),
|
|
7
7
|
offset: z.number().int().min(1).optional().describe("Starting line number (1-based, optional)")
|
|
8
8
|
}).strict();
|
|
9
|
-
function createReadFileTool(
|
|
10
|
-
|
|
11
|
-
let pendingApprovalParentDir;
|
|
12
|
-
return {
|
|
9
|
+
function createReadFileTool(getFileSystemService) {
|
|
10
|
+
return defineTool({
|
|
13
11
|
id: "read_file",
|
|
12
|
+
displayName: "Read",
|
|
13
|
+
aliases: ["read"],
|
|
14
14
|
description: "Read the contents of a file with optional pagination. Returns file content, line count, encoding, and whether the output was truncated. Use limit and offset parameters for large files to read specific sections. This tool is for reading files within allowed paths only.",
|
|
15
15
|
inputSchema: ReadFileInputSchema,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
if (isAllowed) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
if (directoryApproval?.isSessionApproved(file_path)) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
const absolutePath = path.resolve(file_path);
|
|
31
|
-
const parentDir = path.dirname(absolutePath);
|
|
32
|
-
pendingApprovalParentDir = parentDir;
|
|
33
|
-
return {
|
|
34
|
-
type: ApprovalType.DIRECTORY_ACCESS,
|
|
35
|
-
metadata: {
|
|
36
|
-
path: absolutePath,
|
|
37
|
-
parentDir,
|
|
38
|
-
operation: "read",
|
|
39
|
-
toolName: "read_file"
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
},
|
|
43
|
-
/**
|
|
44
|
-
* Handle approved directory access - remember the directory for session
|
|
45
|
-
*/
|
|
46
|
-
onApprovalGranted: (response) => {
|
|
47
|
-
if (!directoryApproval || !pendingApprovalParentDir) return;
|
|
48
|
-
const data = response.data;
|
|
49
|
-
const rememberDirectory = data?.rememberDirectory ?? false;
|
|
50
|
-
directoryApproval.addApproved(
|
|
51
|
-
pendingApprovalParentDir,
|
|
52
|
-
rememberDirectory ? "session" : "once"
|
|
53
|
-
);
|
|
54
|
-
pendingApprovalParentDir = void 0;
|
|
55
|
-
},
|
|
56
|
-
execute: async (input, _context) => {
|
|
16
|
+
...createDirectoryAccessApprovalHandlers({
|
|
17
|
+
toolName: "read_file",
|
|
18
|
+
operation: "read",
|
|
19
|
+
getFileSystemService,
|
|
20
|
+
resolvePaths: (input, fileSystemService) => resolveFilePath(fileSystemService.getWorkingDirectory(), input.file_path)
|
|
21
|
+
}),
|
|
22
|
+
async execute(input, context) {
|
|
23
|
+
const resolvedFileSystemService = await getFileSystemService(context);
|
|
57
24
|
const { file_path, limit, offset } = input;
|
|
58
|
-
const
|
|
25
|
+
const { path: resolvedPath } = resolveFilePath(
|
|
26
|
+
resolvedFileSystemService.getWorkingDirectory(),
|
|
27
|
+
file_path
|
|
28
|
+
);
|
|
29
|
+
const result = await resolvedFileSystemService.readFile(resolvedPath, {
|
|
59
30
|
limit,
|
|
60
31
|
offset
|
|
61
32
|
});
|
|
62
33
|
const _display = {
|
|
63
34
|
type: "file",
|
|
64
|
-
path:
|
|
35
|
+
path: resolvedPath,
|
|
65
36
|
operation: "read",
|
|
66
37
|
size: result.size,
|
|
67
38
|
lineCount: result.lines
|
|
@@ -76,7 +47,7 @@ function createReadFileTool(options) {
|
|
|
76
47
|
_display
|
|
77
48
|
};
|
|
78
49
|
}
|
|
79
|
-
};
|
|
50
|
+
});
|
|
80
51
|
}
|
|
81
52
|
export {
|
|
82
53
|
createReadFileTool
|
|
@@ -0,0 +1,61 @@
|
|
|
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 tool_factory_config_exports = {};
|
|
20
|
+
__export(tool_factory_config_exports, {
|
|
21
|
+
FILESYSTEM_TOOL_NAMES: () => FILESYSTEM_TOOL_NAMES,
|
|
22
|
+
FileSystemToolsConfigSchema: () => FileSystemToolsConfigSchema
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(tool_factory_config_exports);
|
|
25
|
+
var import_zod = require("zod");
|
|
26
|
+
const DEFAULT_ALLOWED_PATHS = ["."];
|
|
27
|
+
const DEFAULT_BLOCKED_PATHS = [".git", "node_modules/.bin", ".env"];
|
|
28
|
+
const DEFAULT_BLOCKED_EXTENSIONS = [".exe", ".dll", ".so"];
|
|
29
|
+
const DEFAULT_MAX_FILE_SIZE = 10 * 1024 * 1024;
|
|
30
|
+
const DEFAULT_ENABLE_BACKUPS = false;
|
|
31
|
+
const DEFAULT_BACKUP_RETENTION_DAYS = 7;
|
|
32
|
+
const FILESYSTEM_TOOL_NAMES = [
|
|
33
|
+
"read_file",
|
|
34
|
+
"write_file",
|
|
35
|
+
"edit_file",
|
|
36
|
+
"glob_files",
|
|
37
|
+
"grep_content"
|
|
38
|
+
];
|
|
39
|
+
const FileSystemToolsConfigSchema = import_zod.z.object({
|
|
40
|
+
type: import_zod.z.literal("filesystem-tools"),
|
|
41
|
+
allowedPaths: import_zod.z.array(import_zod.z.string()).default(DEFAULT_ALLOWED_PATHS).describe("List of allowed base paths for file operations"),
|
|
42
|
+
blockedPaths: import_zod.z.array(import_zod.z.string()).default(DEFAULT_BLOCKED_PATHS).describe("List of blocked paths to exclude from operations"),
|
|
43
|
+
blockedExtensions: import_zod.z.array(import_zod.z.string()).default(DEFAULT_BLOCKED_EXTENSIONS).describe("List of blocked file extensions"),
|
|
44
|
+
maxFileSize: import_zod.z.number().int().positive().default(DEFAULT_MAX_FILE_SIZE).describe(
|
|
45
|
+
`Maximum file size in bytes (default: ${DEFAULT_MAX_FILE_SIZE / 1024 / 1024}MB)`
|
|
46
|
+
),
|
|
47
|
+
workingDirectory: import_zod.z.string().optional().describe("Working directory for file operations (defaults to process.cwd())"),
|
|
48
|
+
enableBackups: import_zod.z.boolean().default(DEFAULT_ENABLE_BACKUPS).describe("Enable automatic backups of modified files"),
|
|
49
|
+
backupPath: import_zod.z.string().optional().describe("Absolute path for storing file backups (if enableBackups is true)"),
|
|
50
|
+
backupRetentionDays: import_zod.z.number().int().positive().default(DEFAULT_BACKUP_RETENTION_DAYS).describe(
|
|
51
|
+
`Number of days to retain backup files (default: ${DEFAULT_BACKUP_RETENTION_DAYS})`
|
|
52
|
+
),
|
|
53
|
+
enabledTools: import_zod.z.array(import_zod.z.enum(FILESYSTEM_TOOL_NAMES)).optional().describe(
|
|
54
|
+
`Subset of tools to enable. If not specified, all tools are enabled. Available: ${FILESYSTEM_TOOL_NAMES.join(", ")}`
|
|
55
|
+
)
|
|
56
|
+
}).strict();
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
FILESYSTEM_TOOL_NAMES,
|
|
60
|
+
FileSystemToolsConfigSchema
|
|
61
|
+
});
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { CustomToolProvider } from '@dexto/core';
|
|
3
|
-
export { FileToolOptions } from './file-tool-types.js';
|
|
4
|
-
import './filesystem-service.js';
|
|
5
|
-
import './types.js';
|
|
6
2
|
|
|
7
3
|
/**
|
|
8
|
-
* FileSystem Tools
|
|
4
|
+
* FileSystem Tools Factory
|
|
9
5
|
*
|
|
10
6
|
* Provides file operation tools by wrapping FileSystemService.
|
|
11
|
-
* When registered, the
|
|
7
|
+
* When registered, the factory initializes FileSystemService and creates tools
|
|
12
8
|
* for file operations (read, write, edit, glob, grep).
|
|
13
9
|
*/
|
|
14
10
|
|
|
15
11
|
/**
|
|
16
|
-
*
|
|
12
|
+
* Available filesystem tool names for enabledTools configuration.
|
|
13
|
+
*/
|
|
14
|
+
declare const FILESYSTEM_TOOL_NAMES: readonly ["read_file", "write_file", "edit_file", "glob_files", "grep_content"];
|
|
15
|
+
/**
|
|
16
|
+
* Configuration schema for FileSystem tools factory.
|
|
17
17
|
*
|
|
18
18
|
* This is the SINGLE SOURCE OF TRUTH for all configuration:
|
|
19
19
|
* - Validation rules
|
|
@@ -36,13 +36,13 @@ declare const FileSystemToolsConfigSchema: z.ZodObject<{
|
|
|
36
36
|
backupRetentionDays: z.ZodDefault<z.ZodNumber>;
|
|
37
37
|
enabledTools: z.ZodOptional<z.ZodArray<z.ZodEnum<["read_file", "write_file", "edit_file", "glob_files", "grep_content"]>, "many">>;
|
|
38
38
|
}, "strict", z.ZodTypeAny, {
|
|
39
|
+
type: "filesystem-tools";
|
|
39
40
|
allowedPaths: string[];
|
|
40
41
|
blockedExtensions: string[];
|
|
41
42
|
blockedPaths: string[];
|
|
42
43
|
maxFileSize: number;
|
|
43
44
|
enableBackups: boolean;
|
|
44
45
|
backupRetentionDays: number;
|
|
45
|
-
type: "filesystem-tools";
|
|
46
46
|
backupPath?: string | undefined;
|
|
47
47
|
workingDirectory?: string | undefined;
|
|
48
48
|
enabledTools?: ("edit_file" | "glob_files" | "grep_content" | "read_file" | "write_file")[] | undefined;
|
|
@@ -59,19 +59,5 @@ declare const FileSystemToolsConfigSchema: z.ZodObject<{
|
|
|
59
59
|
enabledTools?: ("edit_file" | "glob_files" | "grep_content" | "read_file" | "write_file")[] | undefined;
|
|
60
60
|
}>;
|
|
61
61
|
type FileSystemToolsConfig = z.output<typeof FileSystemToolsConfigSchema>;
|
|
62
|
-
/**
|
|
63
|
-
* FileSystem tools provider.
|
|
64
|
-
*
|
|
65
|
-
* Wraps FileSystemService and provides file operation tools:
|
|
66
|
-
* - read_file: Read file contents with pagination
|
|
67
|
-
* - write_file: Write or overwrite file contents
|
|
68
|
-
* - edit_file: Edit files using search/replace operations
|
|
69
|
-
* - glob_files: Find files matching glob patterns
|
|
70
|
-
* - grep_content: Search file contents using regex
|
|
71
|
-
*
|
|
72
|
-
* When registered via customToolRegistry, FileSystemService is automatically
|
|
73
|
-
* initialized and file operation tools become available to the agent.
|
|
74
|
-
*/
|
|
75
|
-
declare const fileSystemToolsProvider: CustomToolProvider<'filesystem-tools', FileSystemToolsConfig>;
|
|
76
62
|
|
|
77
|
-
export {
|
|
63
|
+
export { FILESYSTEM_TOOL_NAMES, type FileSystemToolsConfig, FileSystemToolsConfigSchema };
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { CustomToolProvider } from '@dexto/core';
|
|
3
|
-
export { FileToolOptions } from './file-tool-types.cjs';
|
|
4
|
-
import './filesystem-service.cjs';
|
|
5
|
-
import './types.cjs';
|
|
6
|
-
|
|
7
1
|
/**
|
|
8
|
-
* FileSystem Tools
|
|
2
|
+
* FileSystem Tools Factory
|
|
9
3
|
*
|
|
10
4
|
* Provides file operation tools by wrapping FileSystemService.
|
|
11
|
-
* When registered, the
|
|
5
|
+
* When registered, the factory initializes FileSystemService and creates tools
|
|
12
6
|
* for file operations (read, write, edit, glob, grep).
|
|
13
7
|
*/
|
|
14
|
-
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
/**
|
|
10
|
+
* Available filesystem tool names for enabledTools configuration.
|
|
11
|
+
*/
|
|
12
|
+
export declare const FILESYSTEM_TOOL_NAMES: readonly ["read_file", "write_file", "edit_file", "glob_files", "grep_content"];
|
|
15
13
|
/**
|
|
16
|
-
* Configuration schema for FileSystem tools
|
|
14
|
+
* Configuration schema for FileSystem tools factory.
|
|
17
15
|
*
|
|
18
16
|
* This is the SINGLE SOURCE OF TRUTH for all configuration:
|
|
19
17
|
* - Validation rules
|
|
@@ -24,7 +22,7 @@ import './types.cjs';
|
|
|
24
22
|
* Services receive fully-validated config from this schema and use it as-is,
|
|
25
23
|
* with no additional defaults or fallbacks needed.
|
|
26
24
|
*/
|
|
27
|
-
declare const FileSystemToolsConfigSchema: z.ZodObject<{
|
|
25
|
+
export declare const FileSystemToolsConfigSchema: z.ZodObject<{
|
|
28
26
|
type: z.ZodLiteral<"filesystem-tools">;
|
|
29
27
|
allowedPaths: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
30
28
|
blockedPaths: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
@@ -45,7 +43,7 @@ declare const FileSystemToolsConfigSchema: z.ZodObject<{
|
|
|
45
43
|
type: "filesystem-tools";
|
|
46
44
|
backupPath?: string | undefined;
|
|
47
45
|
workingDirectory?: string | undefined;
|
|
48
|
-
enabledTools?: ("
|
|
46
|
+
enabledTools?: ("read_file" | "write_file" | "edit_file" | "glob_files" | "grep_content")[] | undefined;
|
|
49
47
|
}, {
|
|
50
48
|
type: "filesystem-tools";
|
|
51
49
|
allowedPaths?: string[] | undefined;
|
|
@@ -56,22 +54,7 @@ declare const FileSystemToolsConfigSchema: z.ZodObject<{
|
|
|
56
54
|
enableBackups?: boolean | undefined;
|
|
57
55
|
backupRetentionDays?: number | undefined;
|
|
58
56
|
workingDirectory?: string | undefined;
|
|
59
|
-
enabledTools?: ("
|
|
57
|
+
enabledTools?: ("read_file" | "write_file" | "edit_file" | "glob_files" | "grep_content")[] | undefined;
|
|
60
58
|
}>;
|
|
61
|
-
type FileSystemToolsConfig = z.output<typeof FileSystemToolsConfigSchema>;
|
|
62
|
-
|
|
63
|
-
* FileSystem tools provider.
|
|
64
|
-
*
|
|
65
|
-
* Wraps FileSystemService and provides file operation tools:
|
|
66
|
-
* - read_file: Read file contents with pagination
|
|
67
|
-
* - write_file: Write or overwrite file contents
|
|
68
|
-
* - edit_file: Edit files using search/replace operations
|
|
69
|
-
* - glob_files: Find files matching glob patterns
|
|
70
|
-
* - grep_content: Search file contents using regex
|
|
71
|
-
*
|
|
72
|
-
* When registered via customToolRegistry, FileSystemService is automatically
|
|
73
|
-
* initialized and file operation tools become available to the agent.
|
|
74
|
-
*/
|
|
75
|
-
declare const fileSystemToolsProvider: CustomToolProvider<'filesystem-tools', FileSystemToolsConfig>;
|
|
76
|
-
|
|
77
|
-
export { fileSystemToolsProvider };
|
|
59
|
+
export type FileSystemToolsConfig = z.output<typeof FileSystemToolsConfigSchema>;
|
|
60
|
+
//# sourceMappingURL=tool-factory-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-factory-config.d.ts","sourceRoot":"","sources":["../src/tool-factory-config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB;;GAEG;AACH,eAAO,MAAM,qBAAqB,iFAMxB,CAAC;AAEX;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkD3B,CAAC;AAEd,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,2BAA2B,CAAC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const DEFAULT_ALLOWED_PATHS = ["."];
|
|
3
|
+
const DEFAULT_BLOCKED_PATHS = [".git", "node_modules/.bin", ".env"];
|
|
4
|
+
const DEFAULT_BLOCKED_EXTENSIONS = [".exe", ".dll", ".so"];
|
|
5
|
+
const DEFAULT_MAX_FILE_SIZE = 10 * 1024 * 1024;
|
|
6
|
+
const DEFAULT_ENABLE_BACKUPS = false;
|
|
7
|
+
const DEFAULT_BACKUP_RETENTION_DAYS = 7;
|
|
8
|
+
const FILESYSTEM_TOOL_NAMES = [
|
|
9
|
+
"read_file",
|
|
10
|
+
"write_file",
|
|
11
|
+
"edit_file",
|
|
12
|
+
"glob_files",
|
|
13
|
+
"grep_content"
|
|
14
|
+
];
|
|
15
|
+
const FileSystemToolsConfigSchema = z.object({
|
|
16
|
+
type: z.literal("filesystem-tools"),
|
|
17
|
+
allowedPaths: z.array(z.string()).default(DEFAULT_ALLOWED_PATHS).describe("List of allowed base paths for file operations"),
|
|
18
|
+
blockedPaths: z.array(z.string()).default(DEFAULT_BLOCKED_PATHS).describe("List of blocked paths to exclude from operations"),
|
|
19
|
+
blockedExtensions: z.array(z.string()).default(DEFAULT_BLOCKED_EXTENSIONS).describe("List of blocked file extensions"),
|
|
20
|
+
maxFileSize: z.number().int().positive().default(DEFAULT_MAX_FILE_SIZE).describe(
|
|
21
|
+
`Maximum file size in bytes (default: ${DEFAULT_MAX_FILE_SIZE / 1024 / 1024}MB)`
|
|
22
|
+
),
|
|
23
|
+
workingDirectory: z.string().optional().describe("Working directory for file operations (defaults to process.cwd())"),
|
|
24
|
+
enableBackups: z.boolean().default(DEFAULT_ENABLE_BACKUPS).describe("Enable automatic backups of modified files"),
|
|
25
|
+
backupPath: z.string().optional().describe("Absolute path for storing file backups (if enableBackups is true)"),
|
|
26
|
+
backupRetentionDays: z.number().int().positive().default(DEFAULT_BACKUP_RETENTION_DAYS).describe(
|
|
27
|
+
`Number of days to retain backup files (default: ${DEFAULT_BACKUP_RETENTION_DAYS})`
|
|
28
|
+
),
|
|
29
|
+
enabledTools: z.array(z.enum(FILESYSTEM_TOOL_NAMES)).optional().describe(
|
|
30
|
+
`Subset of tools to enable. If not specified, all tools are enabled. Available: ${FILESYSTEM_TOOL_NAMES.join(", ")}`
|
|
31
|
+
)
|
|
32
|
+
}).strict();
|
|
33
|
+
export {
|
|
34
|
+
FILESYSTEM_TOOL_NAMES,
|
|
35
|
+
FileSystemToolsConfigSchema
|
|
36
|
+
};
|
|
@@ -0,0 +1,102 @@
|
|
|
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 tool_factory_exports = {};
|
|
20
|
+
__export(tool_factory_exports, {
|
|
21
|
+
fileSystemToolsFactory: () => fileSystemToolsFactory
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(tool_factory_exports);
|
|
24
|
+
var import_core = require("@dexto/core");
|
|
25
|
+
var import_filesystem_service = require("./filesystem-service.js");
|
|
26
|
+
var import_read_file_tool = require("./read-file-tool.js");
|
|
27
|
+
var import_write_file_tool = require("./write-file-tool.js");
|
|
28
|
+
var import_edit_file_tool = require("./edit-file-tool.js");
|
|
29
|
+
var import_glob_files_tool = require("./glob-files-tool.js");
|
|
30
|
+
var import_grep_content_tool = require("./grep-content-tool.js");
|
|
31
|
+
var import_tool_factory_config = require("./tool-factory-config.js");
|
|
32
|
+
const fileSystemToolsFactory = {
|
|
33
|
+
configSchema: import_tool_factory_config.FileSystemToolsConfigSchema,
|
|
34
|
+
metadata: {
|
|
35
|
+
displayName: "Filesystem Tools",
|
|
36
|
+
description: "File system operations (read, write, edit, glob, grep)",
|
|
37
|
+
category: "filesystem"
|
|
38
|
+
},
|
|
39
|
+
create: (config) => {
|
|
40
|
+
const fileSystemConfig = {
|
|
41
|
+
allowedPaths: config.allowedPaths,
|
|
42
|
+
blockedPaths: config.blockedPaths,
|
|
43
|
+
blockedExtensions: config.blockedExtensions,
|
|
44
|
+
maxFileSize: config.maxFileSize,
|
|
45
|
+
workingDirectory: config.workingDirectory ?? process.cwd(),
|
|
46
|
+
enableBackups: config.enableBackups,
|
|
47
|
+
backupPath: config.backupPath,
|
|
48
|
+
backupRetentionDays: config.backupRetentionDays
|
|
49
|
+
};
|
|
50
|
+
let fileSystemService;
|
|
51
|
+
const resolveWorkingDirectory = (context) => context.workspace?.path ?? fileSystemConfig.workingDirectory ?? process.cwd();
|
|
52
|
+
const applyWorkspace = (context, service) => {
|
|
53
|
+
const workingDirectory = resolveWorkingDirectory(context);
|
|
54
|
+
service.setWorkingDirectory(workingDirectory);
|
|
55
|
+
};
|
|
56
|
+
const getFileSystemService = async (context) => {
|
|
57
|
+
if (fileSystemService) {
|
|
58
|
+
const approvalManager2 = context.services?.approval;
|
|
59
|
+
if (!approvalManager2) {
|
|
60
|
+
throw import_core.ToolError.configInvalid(
|
|
61
|
+
"filesystem-tools requires ToolExecutionContext.services.approval"
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
fileSystemService.setDirectoryApprovalChecker(
|
|
65
|
+
(filePath) => approvalManager2.isDirectoryApproved(filePath)
|
|
66
|
+
);
|
|
67
|
+
applyWorkspace(context, fileSystemService);
|
|
68
|
+
return fileSystemService;
|
|
69
|
+
}
|
|
70
|
+
const logger = context.logger;
|
|
71
|
+
fileSystemService = new import_filesystem_service.FileSystemService(fileSystemConfig, logger);
|
|
72
|
+
const approvalManager = context.services?.approval;
|
|
73
|
+
if (!approvalManager) {
|
|
74
|
+
throw import_core.ToolError.configInvalid(
|
|
75
|
+
"filesystem-tools requires ToolExecutionContext.services.approval"
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
fileSystemService.setDirectoryApprovalChecker(
|
|
79
|
+
(filePath) => approvalManager.isDirectoryApproved(filePath)
|
|
80
|
+
);
|
|
81
|
+
applyWorkspace(context, fileSystemService);
|
|
82
|
+
fileSystemService.initialize().catch((error) => {
|
|
83
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
84
|
+
logger.error(`Failed to initialize FileSystemService: ${message}`);
|
|
85
|
+
});
|
|
86
|
+
return fileSystemService;
|
|
87
|
+
};
|
|
88
|
+
const toolCreators = {
|
|
89
|
+
read_file: () => (0, import_read_file_tool.createReadFileTool)(getFileSystemService),
|
|
90
|
+
write_file: () => (0, import_write_file_tool.createWriteFileTool)(getFileSystemService),
|
|
91
|
+
edit_file: () => (0, import_edit_file_tool.createEditFileTool)(getFileSystemService),
|
|
92
|
+
glob_files: () => (0, import_glob_files_tool.createGlobFilesTool)(getFileSystemService),
|
|
93
|
+
grep_content: () => (0, import_grep_content_tool.createGrepContentTool)(getFileSystemService)
|
|
94
|
+
};
|
|
95
|
+
const toolsToCreate = config.enabledTools ?? import_tool_factory_config.FILESYSTEM_TOOL_NAMES;
|
|
96
|
+
return toolsToCreate.map((toolName) => toolCreators[toolName]());
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
+
0 && (module.exports = {
|
|
101
|
+
fileSystemToolsFactory
|
|
102
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-factory.d.ts","sourceRoot":"","sources":["../src/tool-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AASvD,OAAO,EAGH,KAAK,qBAAqB,EAC7B,MAAM,0BAA0B,CAAC;AAKlC,eAAO,MAAM,sBAAsB,EAAE,WAAW,CAAC,qBAAqB,CAgFrE,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ToolError } from "@dexto/core";
|
|
2
|
+
import { FileSystemService } from "./filesystem-service.js";
|
|
3
|
+
import { createReadFileTool } from "./read-file-tool.js";
|
|
4
|
+
import { createWriteFileTool } from "./write-file-tool.js";
|
|
5
|
+
import { createEditFileTool } from "./edit-file-tool.js";
|
|
6
|
+
import { createGlobFilesTool } from "./glob-files-tool.js";
|
|
7
|
+
import { createGrepContentTool } from "./grep-content-tool.js";
|
|
8
|
+
import {
|
|
9
|
+
FILESYSTEM_TOOL_NAMES,
|
|
10
|
+
FileSystemToolsConfigSchema
|
|
11
|
+
} from "./tool-factory-config.js";
|
|
12
|
+
const fileSystemToolsFactory = {
|
|
13
|
+
configSchema: FileSystemToolsConfigSchema,
|
|
14
|
+
metadata: {
|
|
15
|
+
displayName: "Filesystem Tools",
|
|
16
|
+
description: "File system operations (read, write, edit, glob, grep)",
|
|
17
|
+
category: "filesystem"
|
|
18
|
+
},
|
|
19
|
+
create: (config) => {
|
|
20
|
+
const fileSystemConfig = {
|
|
21
|
+
allowedPaths: config.allowedPaths,
|
|
22
|
+
blockedPaths: config.blockedPaths,
|
|
23
|
+
blockedExtensions: config.blockedExtensions,
|
|
24
|
+
maxFileSize: config.maxFileSize,
|
|
25
|
+
workingDirectory: config.workingDirectory ?? process.cwd(),
|
|
26
|
+
enableBackups: config.enableBackups,
|
|
27
|
+
backupPath: config.backupPath,
|
|
28
|
+
backupRetentionDays: config.backupRetentionDays
|
|
29
|
+
};
|
|
30
|
+
let fileSystemService;
|
|
31
|
+
const resolveWorkingDirectory = (context) => context.workspace?.path ?? fileSystemConfig.workingDirectory ?? process.cwd();
|
|
32
|
+
const applyWorkspace = (context, service) => {
|
|
33
|
+
const workingDirectory = resolveWorkingDirectory(context);
|
|
34
|
+
service.setWorkingDirectory(workingDirectory);
|
|
35
|
+
};
|
|
36
|
+
const getFileSystemService = async (context) => {
|
|
37
|
+
if (fileSystemService) {
|
|
38
|
+
const approvalManager2 = context.services?.approval;
|
|
39
|
+
if (!approvalManager2) {
|
|
40
|
+
throw ToolError.configInvalid(
|
|
41
|
+
"filesystem-tools requires ToolExecutionContext.services.approval"
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
fileSystemService.setDirectoryApprovalChecker(
|
|
45
|
+
(filePath) => approvalManager2.isDirectoryApproved(filePath)
|
|
46
|
+
);
|
|
47
|
+
applyWorkspace(context, fileSystemService);
|
|
48
|
+
return fileSystemService;
|
|
49
|
+
}
|
|
50
|
+
const logger = context.logger;
|
|
51
|
+
fileSystemService = new FileSystemService(fileSystemConfig, logger);
|
|
52
|
+
const approvalManager = context.services?.approval;
|
|
53
|
+
if (!approvalManager) {
|
|
54
|
+
throw ToolError.configInvalid(
|
|
55
|
+
"filesystem-tools requires ToolExecutionContext.services.approval"
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
fileSystemService.setDirectoryApprovalChecker(
|
|
59
|
+
(filePath) => approvalManager.isDirectoryApproved(filePath)
|
|
60
|
+
);
|
|
61
|
+
applyWorkspace(context, fileSystemService);
|
|
62
|
+
fileSystemService.initialize().catch((error) => {
|
|
63
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
64
|
+
logger.error(`Failed to initialize FileSystemService: ${message}`);
|
|
65
|
+
});
|
|
66
|
+
return fileSystemService;
|
|
67
|
+
};
|
|
68
|
+
const toolCreators = {
|
|
69
|
+
read_file: () => createReadFileTool(getFileSystemService),
|
|
70
|
+
write_file: () => createWriteFileTool(getFileSystemService),
|
|
71
|
+
edit_file: () => createEditFileTool(getFileSystemService),
|
|
72
|
+
glob_files: () => createGlobFilesTool(getFileSystemService),
|
|
73
|
+
grep_content: () => createGrepContentTool(getFileSystemService)
|
|
74
|
+
};
|
|
75
|
+
const toolsToCreate = config.enabledTools ?? FILESYSTEM_TOOL_NAMES;
|
|
76
|
+
return toolsToCreate.map((toolName) => toolCreators[toolName]());
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
export {
|
|
80
|
+
fileSystemToolsFactory
|
|
81
|
+
};
|