@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,108 @@
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_provider_exports = {};
20
+ __export(tool_provider_exports, {
21
+ fileSystemToolsProvider: () => fileSystemToolsProvider
22
+ });
23
+ module.exports = __toCommonJS(tool_provider_exports);
24
+ var import_zod = require("zod");
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
+ const DEFAULT_ALLOWED_PATHS = ["."];
32
+ const DEFAULT_BLOCKED_PATHS = [".git", "node_modules/.bin", ".env"];
33
+ const DEFAULT_BLOCKED_EXTENSIONS = [".exe", ".dll", ".so"];
34
+ const DEFAULT_MAX_FILE_SIZE = 10 * 1024 * 1024;
35
+ const DEFAULT_ENABLE_BACKUPS = false;
36
+ const DEFAULT_BACKUP_RETENTION_DAYS = 7;
37
+ const FileSystemToolsConfigSchema = import_zod.z.object({
38
+ type: import_zod.z.literal("filesystem-tools"),
39
+ allowedPaths: import_zod.z.array(import_zod.z.string()).default(DEFAULT_ALLOWED_PATHS).describe("List of allowed base paths for file operations"),
40
+ blockedPaths: import_zod.z.array(import_zod.z.string()).default(DEFAULT_BLOCKED_PATHS).describe("List of blocked paths to exclude from operations"),
41
+ blockedExtensions: import_zod.z.array(import_zod.z.string()).default(DEFAULT_BLOCKED_EXTENSIONS).describe("List of blocked file extensions"),
42
+ maxFileSize: import_zod.z.number().int().positive().default(DEFAULT_MAX_FILE_SIZE).describe(
43
+ `Maximum file size in bytes (default: ${DEFAULT_MAX_FILE_SIZE / 1024 / 1024}MB)`
44
+ ),
45
+ workingDirectory: import_zod.z.string().optional().describe("Working directory for file operations (defaults to process.cwd())"),
46
+ enableBackups: import_zod.z.boolean().default(DEFAULT_ENABLE_BACKUPS).describe("Enable automatic backups of modified files"),
47
+ backupPath: import_zod.z.string().optional().describe("Absolute path for storing file backups (if enableBackups is true)"),
48
+ backupRetentionDays: import_zod.z.number().int().positive().default(DEFAULT_BACKUP_RETENTION_DAYS).describe(
49
+ `Number of days to retain backup files (default: ${DEFAULT_BACKUP_RETENTION_DAYS})`
50
+ )
51
+ }).strict();
52
+ const fileSystemToolsProvider = {
53
+ type: "filesystem-tools",
54
+ configSchema: FileSystemToolsConfigSchema,
55
+ create: (config, context) => {
56
+ const { logger, services } = context;
57
+ logger.debug("Creating FileSystemService for filesystem tools");
58
+ const fileSystemService = new import_filesystem_service.FileSystemService(
59
+ {
60
+ allowedPaths: config.allowedPaths,
61
+ blockedPaths: config.blockedPaths,
62
+ blockedExtensions: config.blockedExtensions,
63
+ maxFileSize: config.maxFileSize,
64
+ workingDirectory: config.workingDirectory || process.cwd(),
65
+ enableBackups: config.enableBackups,
66
+ backupPath: config.backupPath,
67
+ backupRetentionDays: config.backupRetentionDays
68
+ },
69
+ logger
70
+ );
71
+ fileSystemService.initialize().catch((error) => {
72
+ logger.error(`Failed to initialize FileSystemService: ${error.message}`);
73
+ });
74
+ logger.debug("FileSystemService created - initialization will complete on first tool use");
75
+ const approvalManager = services?.approvalManager;
76
+ if (approvalManager) {
77
+ const approvalChecker = (filePath) => {
78
+ return approvalManager.isDirectoryApproved(filePath);
79
+ };
80
+ fileSystemService.setDirectoryApprovalChecker(approvalChecker);
81
+ logger.debug("Directory approval checker configured for FileSystemService");
82
+ }
83
+ const directoryApproval = approvalManager ? {
84
+ isSessionApproved: (filePath) => approvalManager.isDirectorySessionApproved(filePath),
85
+ addApproved: (directory, type) => approvalManager.addApprovedDirectory(directory, type)
86
+ } : void 0;
87
+ const fileToolOptions = {
88
+ fileSystemService,
89
+ directoryApproval
90
+ };
91
+ return [
92
+ (0, import_read_file_tool.createReadFileTool)(fileToolOptions),
93
+ (0, import_write_file_tool.createWriteFileTool)(fileToolOptions),
94
+ (0, import_edit_file_tool.createEditFileTool)(fileToolOptions),
95
+ (0, import_glob_files_tool.createGlobFilesTool)(fileSystemService),
96
+ (0, import_grep_content_tool.createGrepContentTool)(fileSystemService)
97
+ ];
98
+ },
99
+ metadata: {
100
+ displayName: "FileSystem Tools",
101
+ description: "File system operations (read, write, edit, glob, grep)",
102
+ category: "filesystem"
103
+ }
104
+ };
105
+ // Annotate the CommonJS export names for ESM import in node:
106
+ 0 && (module.exports = {
107
+ fileSystemToolsProvider
108
+ });
@@ -0,0 +1,74 @@
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
+ /**
8
+ * FileSystem Tools Provider
9
+ *
10
+ * Provides file operation tools by wrapping FileSystemService.
11
+ * When registered, the provider initializes FileSystemService and creates tools
12
+ * for file operations (read, write, edit, glob, grep).
13
+ */
14
+
15
+ /**
16
+ * Configuration schema for FileSystem tools provider.
17
+ *
18
+ * This is the SINGLE SOURCE OF TRUTH for all configuration:
19
+ * - Validation rules
20
+ * - Default values (using constants above)
21
+ * - Documentation
22
+ * - Type definitions
23
+ *
24
+ * Services receive fully-validated config from this schema and use it as-is,
25
+ * with no additional defaults or fallbacks needed.
26
+ */
27
+ declare const FileSystemToolsConfigSchema: z.ZodObject<{
28
+ type: z.ZodLiteral<"filesystem-tools">;
29
+ allowedPaths: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
30
+ blockedPaths: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
31
+ blockedExtensions: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
32
+ maxFileSize: z.ZodDefault<z.ZodNumber>;
33
+ workingDirectory: z.ZodOptional<z.ZodString>;
34
+ enableBackups: z.ZodDefault<z.ZodBoolean>;
35
+ backupPath: z.ZodOptional<z.ZodString>;
36
+ backupRetentionDays: z.ZodDefault<z.ZodNumber>;
37
+ }, "strict", z.ZodTypeAny, {
38
+ type: "filesystem-tools";
39
+ allowedPaths: string[];
40
+ blockedExtensions: string[];
41
+ blockedPaths: string[];
42
+ maxFileSize: number;
43
+ enableBackups: boolean;
44
+ backupRetentionDays: number;
45
+ backupPath?: string | undefined;
46
+ workingDirectory?: string | undefined;
47
+ }, {
48
+ type: "filesystem-tools";
49
+ allowedPaths?: string[] | undefined;
50
+ blockedExtensions?: string[] | undefined;
51
+ backupPath?: string | undefined;
52
+ blockedPaths?: string[] | undefined;
53
+ maxFileSize?: number | undefined;
54
+ enableBackups?: boolean | undefined;
55
+ backupRetentionDays?: number | undefined;
56
+ workingDirectory?: string | undefined;
57
+ }>;
58
+ type FileSystemToolsConfig = z.output<typeof FileSystemToolsConfigSchema>;
59
+ /**
60
+ * FileSystem tools provider.
61
+ *
62
+ * Wraps FileSystemService and provides file operation tools:
63
+ * - read_file: Read file contents with pagination
64
+ * - write_file: Write or overwrite file contents
65
+ * - edit_file: Edit files using search/replace operations
66
+ * - glob_files: Find files matching glob patterns
67
+ * - grep_content: Search file contents using regex
68
+ *
69
+ * When registered via customToolRegistry, FileSystemService is automatically
70
+ * initialized and file operation tools become available to the agent.
71
+ */
72
+ declare const fileSystemToolsProvider: CustomToolProvider<'filesystem-tools', FileSystemToolsConfig>;
73
+
74
+ export { fileSystemToolsProvider };
@@ -0,0 +1,74 @@
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
+
7
+ /**
8
+ * FileSystem Tools Provider
9
+ *
10
+ * Provides file operation tools by wrapping FileSystemService.
11
+ * When registered, the provider initializes FileSystemService and creates tools
12
+ * for file operations (read, write, edit, glob, grep).
13
+ */
14
+
15
+ /**
16
+ * Configuration schema for FileSystem tools provider.
17
+ *
18
+ * This is the SINGLE SOURCE OF TRUTH for all configuration:
19
+ * - Validation rules
20
+ * - Default values (using constants above)
21
+ * - Documentation
22
+ * - Type definitions
23
+ *
24
+ * Services receive fully-validated config from this schema and use it as-is,
25
+ * with no additional defaults or fallbacks needed.
26
+ */
27
+ declare const FileSystemToolsConfigSchema: z.ZodObject<{
28
+ type: z.ZodLiteral<"filesystem-tools">;
29
+ allowedPaths: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
30
+ blockedPaths: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
31
+ blockedExtensions: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
32
+ maxFileSize: z.ZodDefault<z.ZodNumber>;
33
+ workingDirectory: z.ZodOptional<z.ZodString>;
34
+ enableBackups: z.ZodDefault<z.ZodBoolean>;
35
+ backupPath: z.ZodOptional<z.ZodString>;
36
+ backupRetentionDays: z.ZodDefault<z.ZodNumber>;
37
+ }, "strict", z.ZodTypeAny, {
38
+ type: "filesystem-tools";
39
+ allowedPaths: string[];
40
+ blockedExtensions: string[];
41
+ blockedPaths: string[];
42
+ maxFileSize: number;
43
+ enableBackups: boolean;
44
+ backupRetentionDays: number;
45
+ backupPath?: string | undefined;
46
+ workingDirectory?: string | undefined;
47
+ }, {
48
+ type: "filesystem-tools";
49
+ allowedPaths?: string[] | undefined;
50
+ blockedExtensions?: string[] | undefined;
51
+ backupPath?: string | undefined;
52
+ blockedPaths?: string[] | undefined;
53
+ maxFileSize?: number | undefined;
54
+ enableBackups?: boolean | undefined;
55
+ backupRetentionDays?: number | undefined;
56
+ workingDirectory?: string | undefined;
57
+ }>;
58
+ type FileSystemToolsConfig = z.output<typeof FileSystemToolsConfigSchema>;
59
+ /**
60
+ * FileSystem tools provider.
61
+ *
62
+ * Wraps FileSystemService and provides file operation tools:
63
+ * - read_file: Read file contents with pagination
64
+ * - write_file: Write or overwrite file contents
65
+ * - edit_file: Edit files using search/replace operations
66
+ * - glob_files: Find files matching glob patterns
67
+ * - grep_content: Search file contents using regex
68
+ *
69
+ * When registered via customToolRegistry, FileSystemService is automatically
70
+ * initialized and file operation tools become available to the agent.
71
+ */
72
+ declare const fileSystemToolsProvider: CustomToolProvider<'filesystem-tools', FileSystemToolsConfig>;
73
+
74
+ export { fileSystemToolsProvider };
@@ -0,0 +1,84 @@
1
+ import { z } from "zod";
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
+ const DEFAULT_ALLOWED_PATHS = ["."];
9
+ const DEFAULT_BLOCKED_PATHS = [".git", "node_modules/.bin", ".env"];
10
+ const DEFAULT_BLOCKED_EXTENSIONS = [".exe", ".dll", ".so"];
11
+ const DEFAULT_MAX_FILE_SIZE = 10 * 1024 * 1024;
12
+ const DEFAULT_ENABLE_BACKUPS = false;
13
+ const DEFAULT_BACKUP_RETENTION_DAYS = 7;
14
+ const FileSystemToolsConfigSchema = z.object({
15
+ type: z.literal("filesystem-tools"),
16
+ allowedPaths: z.array(z.string()).default(DEFAULT_ALLOWED_PATHS).describe("List of allowed base paths for file operations"),
17
+ blockedPaths: z.array(z.string()).default(DEFAULT_BLOCKED_PATHS).describe("List of blocked paths to exclude from operations"),
18
+ blockedExtensions: z.array(z.string()).default(DEFAULT_BLOCKED_EXTENSIONS).describe("List of blocked file extensions"),
19
+ maxFileSize: z.number().int().positive().default(DEFAULT_MAX_FILE_SIZE).describe(
20
+ `Maximum file size in bytes (default: ${DEFAULT_MAX_FILE_SIZE / 1024 / 1024}MB)`
21
+ ),
22
+ workingDirectory: z.string().optional().describe("Working directory for file operations (defaults to process.cwd())"),
23
+ enableBackups: z.boolean().default(DEFAULT_ENABLE_BACKUPS).describe("Enable automatic backups of modified files"),
24
+ backupPath: z.string().optional().describe("Absolute path for storing file backups (if enableBackups is true)"),
25
+ backupRetentionDays: z.number().int().positive().default(DEFAULT_BACKUP_RETENTION_DAYS).describe(
26
+ `Number of days to retain backup files (default: ${DEFAULT_BACKUP_RETENTION_DAYS})`
27
+ )
28
+ }).strict();
29
+ const fileSystemToolsProvider = {
30
+ type: "filesystem-tools",
31
+ configSchema: FileSystemToolsConfigSchema,
32
+ create: (config, context) => {
33
+ const { logger, services } = context;
34
+ logger.debug("Creating FileSystemService for filesystem tools");
35
+ const fileSystemService = new FileSystemService(
36
+ {
37
+ allowedPaths: config.allowedPaths,
38
+ blockedPaths: config.blockedPaths,
39
+ blockedExtensions: config.blockedExtensions,
40
+ maxFileSize: config.maxFileSize,
41
+ workingDirectory: config.workingDirectory || process.cwd(),
42
+ enableBackups: config.enableBackups,
43
+ backupPath: config.backupPath,
44
+ backupRetentionDays: config.backupRetentionDays
45
+ },
46
+ logger
47
+ );
48
+ fileSystemService.initialize().catch((error) => {
49
+ logger.error(`Failed to initialize FileSystemService: ${error.message}`);
50
+ });
51
+ logger.debug("FileSystemService created - initialization will complete on first tool use");
52
+ const approvalManager = services?.approvalManager;
53
+ if (approvalManager) {
54
+ const approvalChecker = (filePath) => {
55
+ return approvalManager.isDirectoryApproved(filePath);
56
+ };
57
+ fileSystemService.setDirectoryApprovalChecker(approvalChecker);
58
+ logger.debug("Directory approval checker configured for FileSystemService");
59
+ }
60
+ const directoryApproval = approvalManager ? {
61
+ isSessionApproved: (filePath) => approvalManager.isDirectorySessionApproved(filePath),
62
+ addApproved: (directory, type) => approvalManager.addApprovedDirectory(directory, type)
63
+ } : void 0;
64
+ const fileToolOptions = {
65
+ fileSystemService,
66
+ directoryApproval
67
+ };
68
+ return [
69
+ createReadFileTool(fileToolOptions),
70
+ createWriteFileTool(fileToolOptions),
71
+ createEditFileTool(fileToolOptions),
72
+ createGlobFilesTool(fileSystemService),
73
+ createGrepContentTool(fileSystemService)
74
+ ];
75
+ },
76
+ metadata: {
77
+ displayName: "FileSystem Tools",
78
+ description: "File system operations (read, write, edit, glob, grep)",
79
+ category: "filesystem"
80
+ }
81
+ };
82
+ export {
83
+ fileSystemToolsProvider
84
+ };
package/dist/types.cjs ADDED
@@ -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 types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);
@@ -0,0 +1,172 @@
1
+ /**
2
+ * FileSystem Service Types
3
+ *
4
+ * Types and interfaces for file system operations including reading, writing,
5
+ * searching, and validation.
6
+ */
7
+ type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex';
8
+ /**
9
+ * File content with metadata
10
+ */
11
+ interface FileContent {
12
+ content: string;
13
+ lines: number;
14
+ encoding: string;
15
+ mimeType?: string;
16
+ truncated: boolean;
17
+ size: number;
18
+ }
19
+ /**
20
+ * Options for reading files
21
+ */
22
+ interface ReadFileOptions {
23
+ /** Maximum number of lines to read */
24
+ limit?: number | undefined;
25
+ /** Starting line number (1-based) */
26
+ offset?: number | undefined;
27
+ /** File encoding (default: utf-8) */
28
+ encoding?: BufferEncoding | undefined;
29
+ }
30
+ /**
31
+ * File metadata for glob results
32
+ */
33
+ interface FileMetadata {
34
+ path: string;
35
+ size: number;
36
+ modified: Date;
37
+ isDirectory: boolean;
38
+ }
39
+ /**
40
+ * Options for glob operations
41
+ */
42
+ interface GlobOptions {
43
+ /** Base directory to search from */
44
+ cwd?: string | undefined;
45
+ /** Maximum number of results */
46
+ maxResults?: number | undefined;
47
+ /** Include file metadata */
48
+ includeMetadata?: boolean | undefined;
49
+ }
50
+ /**
51
+ * Glob result
52
+ */
53
+ interface GlobResult {
54
+ files: FileMetadata[];
55
+ truncated: boolean;
56
+ totalFound: number;
57
+ }
58
+ /**
59
+ * Search match with context
60
+ */
61
+ interface SearchMatch {
62
+ file: string;
63
+ lineNumber: number;
64
+ line: string;
65
+ context?: {
66
+ before: string[];
67
+ after: string[];
68
+ };
69
+ }
70
+ /**
71
+ * Options for content search (grep)
72
+ */
73
+ interface GrepOptions {
74
+ /** Base directory to search */
75
+ path?: string | undefined;
76
+ /** Glob pattern to filter files */
77
+ glob?: string | undefined;
78
+ /** Number of context lines before/after match */
79
+ contextLines?: number | undefined;
80
+ /** Case-insensitive search */
81
+ caseInsensitive?: boolean | undefined;
82
+ /** Maximum number of results */
83
+ maxResults?: number | undefined;
84
+ /** Include line numbers */
85
+ lineNumbers?: boolean | undefined;
86
+ }
87
+ /**
88
+ * Search result
89
+ */
90
+ interface SearchResult {
91
+ matches: SearchMatch[];
92
+ totalMatches: number;
93
+ truncated: boolean;
94
+ filesSearched: number;
95
+ }
96
+ /**
97
+ * Options for writing files
98
+ */
99
+ interface WriteFileOptions {
100
+ /** Create parent directories if they don't exist */
101
+ createDirs?: boolean | undefined;
102
+ /** File encoding (default: utf-8) */
103
+ encoding?: BufferEncoding | undefined;
104
+ /** Create backup before overwriting */
105
+ backup?: boolean | undefined;
106
+ }
107
+ /**
108
+ * Write result
109
+ */
110
+ interface WriteResult {
111
+ success: boolean;
112
+ path: string;
113
+ bytesWritten: number;
114
+ backupPath?: string | undefined;
115
+ }
116
+ /**
117
+ * Edit operation
118
+ */
119
+ interface EditOperation {
120
+ oldString: string;
121
+ newString: string;
122
+ replaceAll?: boolean | undefined;
123
+ }
124
+ /**
125
+ * Options for editing files
126
+ */
127
+ interface EditFileOptions {
128
+ /** Create backup before editing */
129
+ backup?: boolean;
130
+ /** File encoding */
131
+ encoding?: BufferEncoding;
132
+ }
133
+ /**
134
+ * Edit result
135
+ */
136
+ interface EditResult {
137
+ success: boolean;
138
+ path: string;
139
+ changesCount: number;
140
+ backupPath?: string | undefined;
141
+ }
142
+ /**
143
+ * Path validation result
144
+ */
145
+ interface PathValidation {
146
+ isValid: boolean;
147
+ error?: string;
148
+ normalizedPath?: string;
149
+ }
150
+ /**
151
+ * File system configuration
152
+ */
153
+ interface FileSystemConfig {
154
+ /** Allowed base paths */
155
+ allowedPaths: string[];
156
+ /** Blocked paths (relative to allowed paths) */
157
+ blockedPaths: string[];
158
+ /** Blocked file extensions */
159
+ blockedExtensions: string[];
160
+ /** Maximum file size in bytes */
161
+ maxFileSize: number;
162
+ /** Enable automatic backups */
163
+ enableBackups: boolean;
164
+ /** Backup directory absolute path (required when enableBackups is true - provided by CLI enrichment) */
165
+ backupPath?: string | undefined;
166
+ /** Backup retention period in days (default: 7) */
167
+ backupRetentionDays: number;
168
+ /** Working directory for glob/grep operations (defaults to process.cwd()) */
169
+ workingDirectory?: string | undefined;
170
+ }
171
+
172
+ export type { BufferEncoding, EditFileOptions, EditOperation, EditResult, FileContent, FileMetadata, FileSystemConfig, GlobOptions, GlobResult, GrepOptions, PathValidation, ReadFileOptions, SearchMatch, SearchResult, WriteFileOptions, WriteResult };