@dexto/tools-filesystem 1.16.5 → 1.17.0-beta.5
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/blocked-path-check.cjs +62 -0
- package/dist/blocked-path-check.d.ts +11 -0
- package/dist/blocked-path-check.d.ts.map +1 -0
- package/dist/blocked-path-check.js +27 -0
- package/dist/blocked-path-check.test.cjs +117 -0
- package/dist/blocked-path-check.test.d.ts +2 -0
- package/dist/blocked-path-check.test.d.ts.map +1 -0
- package/dist/blocked-path-check.test.js +116 -0
- package/dist/directory-approval.integration.test.cjs +12 -11
- package/dist/directory-approval.integration.test.js +12 -11
- package/dist/edit-file-tool.cjs +48 -27
- package/dist/edit-file-tool.d.ts +2 -1
- package/dist/edit-file-tool.d.ts.map +1 -1
- package/dist/edit-file-tool.js +48 -27
- package/dist/edit-file-tool.test.cjs +161 -30
- package/dist/edit-file-tool.test.js +161 -30
- package/dist/file-size.cjs +47 -0
- package/dist/file-size.d.ts +12 -0
- package/dist/file-size.d.ts.map +1 -0
- package/dist/file-size.js +22 -0
- package/dist/glob-files-tool.cjs +9 -4
- package/dist/glob-files-tool.d.ts +2 -1
- package/dist/glob-files-tool.d.ts.map +1 -1
- package/dist/glob-files-tool.js +9 -4
- package/dist/glob-files-tool.test.cjs +72 -4
- package/dist/glob-files-tool.test.js +72 -4
- package/dist/grep-content-tool.cjs +4 -1
- package/dist/grep-content-tool.d.ts +2 -1
- package/dist/grep-content-tool.d.ts.map +1 -1
- package/dist/grep-content-tool.js +4 -1
- package/dist/grep-content-tool.test.cjs +5 -4
- package/dist/grep-content-tool.test.js +5 -4
- package/dist/index.d.cts +12 -5
- package/dist/path-validator.cjs +26 -1
- package/dist/path-validator.d.ts.map +1 -1
- package/dist/path-validator.js +26 -1
- package/dist/path-validator.test.cjs +75 -0
- package/dist/path-validator.test.js +75 -0
- package/dist/read-file-tool.cjs +14 -2
- package/dist/read-file-tool.d.ts +2 -1
- package/dist/read-file-tool.d.ts.map +1 -1
- package/dist/read-file-tool.js +14 -2
- package/dist/read-file-tool.test.cjs +54 -5
- package/dist/read-file-tool.test.js +54 -5
- package/dist/test-helpers.cjs +28 -0
- package/dist/test-helpers.d.ts +4 -0
- package/dist/test-helpers.d.ts.map +1 -0
- package/dist/test-helpers.js +4 -0
- package/dist/tool-factory-config.d.ts +2 -2
- package/dist/tool-factory.cjs +9 -5
- package/dist/tool-factory.d.ts.map +1 -1
- package/dist/tool-factory.js +9 -5
- package/dist/workspace-paths.cjs +5 -1
- package/dist/workspace-paths.d.ts.map +1 -1
- package/dist/workspace-paths.js +5 -1
- package/dist/write-file-tool.cjs +8 -1
- package/dist/write-file-tool.d.ts +2 -1
- package/dist/write-file-tool.d.ts.map +1 -1
- package/dist/write-file-tool.js +8 -1
- package/dist/write-file-tool.test.cjs +18 -17
- package/dist/write-file-tool.test.js +18 -17
- package/package.json +4 -3
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { describe, it, expect, vi } from "vitest";
|
|
2
2
|
import { ToolErrorCode } from "@dexto/core";
|
|
3
|
+
import { createBlockedPathCheck } from "./blocked-path-check.js";
|
|
3
4
|
import { createGlobFilesTool } from "./glob-files-tool.js";
|
|
5
|
+
import { allowAllPaths } from "./test-helpers.js";
|
|
6
|
+
const blockedPathCheck = createBlockedPathCheck({
|
|
7
|
+
allowedPaths: ["."],
|
|
8
|
+
blockedPaths: [".git", ".env"],
|
|
9
|
+
blockedExtensions: [],
|
|
10
|
+
maxFileSize: 1024,
|
|
11
|
+
enableBackups: false,
|
|
12
|
+
backupRetentionDays: 7
|
|
13
|
+
});
|
|
4
14
|
const createMockLogger = () => {
|
|
5
15
|
const logger = {
|
|
6
16
|
debug: vi.fn(),
|
|
@@ -58,7 +68,7 @@ describe("glob_files tool", () => {
|
|
|
58
68
|
throw new Error("glob_files execute must not use FileSystemService");
|
|
59
69
|
});
|
|
60
70
|
const glob = vi.fn(async () => ["src/a.ts", "src/b.ts", "src/c.ts"]);
|
|
61
|
-
const tool = createGlobFilesTool(getFileSystemService);
|
|
71
|
+
const tool = createGlobFilesTool(getFileSystemService, allowAllPaths);
|
|
62
72
|
const parsedInput = tool.inputSchema.parse({
|
|
63
73
|
pattern: "**/*.ts",
|
|
64
74
|
path: "src",
|
|
@@ -76,7 +86,7 @@ describe("glob_files tool", () => {
|
|
|
76
86
|
it("normalizes workspace-contained absolute search paths before globbing", async () => {
|
|
77
87
|
const mockLogger = createMockLogger();
|
|
78
88
|
const glob = vi.fn(async () => ["src/a.ts"]);
|
|
79
|
-
const tool = createGlobFilesTool(vi.fn());
|
|
89
|
+
const tool = createGlobFilesTool(vi.fn(), allowAllPaths);
|
|
80
90
|
await tool.execute(
|
|
81
91
|
tool.inputSchema.parse({
|
|
82
92
|
pattern: "**/*.ts",
|
|
@@ -89,7 +99,7 @@ describe("glob_files tool", () => {
|
|
|
89
99
|
it("rejects external absolute search paths before file provider calls", async () => {
|
|
90
100
|
const mockLogger = createMockLogger();
|
|
91
101
|
const glob = vi.fn(async () => ["src/a.ts"]);
|
|
92
|
-
const tool = createGlobFilesTool(vi.fn());
|
|
102
|
+
const tool = createGlobFilesTool(vi.fn(), allowAllPaths);
|
|
93
103
|
await expect(
|
|
94
104
|
tool.execute(
|
|
95
105
|
tool.inputSchema.parse({
|
|
@@ -104,7 +114,7 @@ describe("glob_files tool", () => {
|
|
|
104
114
|
it("rejects absolute and escaping glob patterns before file provider calls", async () => {
|
|
105
115
|
const mockLogger = createMockLogger();
|
|
106
116
|
const glob = vi.fn(async () => ["src/a.ts"]);
|
|
107
|
-
const tool = createGlobFilesTool(vi.fn());
|
|
117
|
+
const tool = createGlobFilesTool(vi.fn(), allowAllPaths);
|
|
108
118
|
await expect(
|
|
109
119
|
tool.execute(
|
|
110
120
|
tool.inputSchema.parse({
|
|
@@ -123,4 +133,62 @@ describe("glob_files tool", () => {
|
|
|
123
133
|
).rejects.toMatchObject({ code: ToolErrorCode.VALIDATION_FAILED });
|
|
124
134
|
expect(glob).not.toHaveBeenCalled();
|
|
125
135
|
});
|
|
136
|
+
it.each([
|
|
137
|
+
"{..,src}/**/*.ts",
|
|
138
|
+
"{.,.}{.,.}/secret.txt",
|
|
139
|
+
"{/outside,src}/**/*.ts",
|
|
140
|
+
"src/{a,../b}"
|
|
141
|
+
])("rejects brace pattern %s that expands to an escaping glob", async (pattern) => {
|
|
142
|
+
const glob = vi.fn(async () => ["src/a.ts"]);
|
|
143
|
+
const tool = createGlobFilesTool(vi.fn(), allowAllPaths);
|
|
144
|
+
await expect(
|
|
145
|
+
tool.execute(
|
|
146
|
+
tool.inputSchema.parse({ pattern }),
|
|
147
|
+
createToolContext(createMockLogger(), glob)
|
|
148
|
+
)
|
|
149
|
+
).rejects.toMatchObject({ code: ToolErrorCode.VALIDATION_FAILED });
|
|
150
|
+
expect(glob).not.toHaveBeenCalled();
|
|
151
|
+
});
|
|
152
|
+
it("still accepts brace patterns that stay inside the workspace", async () => {
|
|
153
|
+
const glob = vi.fn(async () => ["src/a.ts", "src/b.tsx"]);
|
|
154
|
+
const tool = createGlobFilesTool(vi.fn(), allowAllPaths);
|
|
155
|
+
await tool.execute(
|
|
156
|
+
tool.inputSchema.parse({ pattern: "src/**/*.{ts,tsx}" }),
|
|
157
|
+
createToolContext(createMockLogger(), glob)
|
|
158
|
+
);
|
|
159
|
+
expect(glob).toHaveBeenCalledWith("src/**/*.{ts,tsx}");
|
|
160
|
+
});
|
|
161
|
+
it("leaves blocked files out of the results", async () => {
|
|
162
|
+
const glob = vi.fn(async () => [".env", "sub/.env", "sub/.git/config", "src/a.ts"]);
|
|
163
|
+
const tool = createGlobFilesTool(vi.fn(), blockedPathCheck);
|
|
164
|
+
const result = await tool.execute(
|
|
165
|
+
tool.inputSchema.parse({ pattern: "**/*" }),
|
|
166
|
+
createToolContext(createMockLogger(), glob)
|
|
167
|
+
);
|
|
168
|
+
expect(result.files).toEqual([{ path: "src/a.ts" }]);
|
|
169
|
+
expect(result.total_found).toBe(1);
|
|
170
|
+
});
|
|
171
|
+
it("checks only the entries it returns, stopping at the result cap", async () => {
|
|
172
|
+
const files = [".env", ...Array.from({ length: 50 }, (_, index) => `src/f${index}.ts`)];
|
|
173
|
+
const glob = vi.fn(async () => files);
|
|
174
|
+
const check = vi.fn(blockedPathCheck);
|
|
175
|
+
const tool = createGlobFilesTool(vi.fn(), check);
|
|
176
|
+
const result = await tool.execute(
|
|
177
|
+
tool.inputSchema.parse({ pattern: "**/*", max_results: 2 }),
|
|
178
|
+
createToolContext(createMockLogger(), glob)
|
|
179
|
+
);
|
|
180
|
+
expect(result.files).toEqual([{ path: "src/f0.ts" }, { path: "src/f1.ts" }]);
|
|
181
|
+
expect(result.truncated).toBe(true);
|
|
182
|
+
expect(check).toHaveBeenCalledTimes(4);
|
|
183
|
+
});
|
|
184
|
+
it("does not report truncation when exactly max_results files are left", async () => {
|
|
185
|
+
const glob = vi.fn(async () => [".env", "src/a.ts", "src/b.ts"]);
|
|
186
|
+
const tool = createGlobFilesTool(vi.fn(), blockedPathCheck);
|
|
187
|
+
const result = await tool.execute(
|
|
188
|
+
tool.inputSchema.parse({ pattern: "**/*", max_results: 2 }),
|
|
189
|
+
createToolContext(createMockLogger(), glob)
|
|
190
|
+
);
|
|
191
|
+
expect(result.files).toHaveLength(2);
|
|
192
|
+
expect(result.truncated).toBe(false);
|
|
193
|
+
});
|
|
126
194
|
});
|
|
@@ -48,7 +48,7 @@ const GrepContentInputSchema = import_zod.z.object({
|
|
|
48
48
|
case_insensitive: import_zod.z.boolean().optional().default(false).describe("Perform case-insensitive search (default: false)"),
|
|
49
49
|
max_results: import_zod.z.number().int().positive().optional().default(100).describe("Maximum number of results to return (default: 100)")
|
|
50
50
|
}).strict();
|
|
51
|
-
function createGrepContentTool(getFileSystemService) {
|
|
51
|
+
function createGrepContentTool(getFileSystemService, blockedPathCheck) {
|
|
52
52
|
return (0, import_tools.defineTool)({
|
|
53
53
|
id: "grep_content",
|
|
54
54
|
aliases: ["grep"],
|
|
@@ -107,6 +107,9 @@ function createGrepContentTool(getFileSystemService) {
|
|
|
107
107
|
const matches = [];
|
|
108
108
|
let filesSearched = 0;
|
|
109
109
|
for (const file of files) {
|
|
110
|
+
if (await blockedPathCheck(handle.context.path, file, context.logger) !== null) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
110
113
|
let content;
|
|
111
114
|
try {
|
|
112
115
|
content = await handle.files.readText(file);
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
import type { Tool } from '@dexto/core/tools';
|
|
8
8
|
import type { FileSystemServiceGetter } from './file-tool-types.js';
|
|
9
|
+
import type { BlockedPathCheck } from './blocked-path-check.js';
|
|
9
10
|
declare const GrepContentInputSchema: z.ZodObject<{
|
|
10
11
|
pattern: z.ZodString;
|
|
11
12
|
path: z.ZodOptional<z.ZodString>;
|
|
@@ -17,6 +18,6 @@ declare const GrepContentInputSchema: z.ZodObject<{
|
|
|
17
18
|
/**
|
|
18
19
|
* Create the grep_content internal tool with directory approval support
|
|
19
20
|
*/
|
|
20
|
-
export declare function createGrepContentTool(getFileSystemService: FileSystemServiceGetter): Tool<typeof GrepContentInputSchema>;
|
|
21
|
+
export declare function createGrepContentTool(getFileSystemService: FileSystemServiceGetter, blockedPathCheck: BlockedPathCheck): Tool<typeof GrepContentInputSchema>;
|
|
21
22
|
export {};
|
|
22
23
|
//# sourceMappingURL=grep-content-tool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grep-content-tool.d.ts","sourceRoot":"","sources":["../src/grep-content-tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,OAAO,KAAK,EAAqB,IAAI,EAAwB,MAAM,mBAAmB,CAAC;AACvF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"grep-content-tool.d.ts","sourceRoot":"","sources":["../src/grep-content-tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,OAAO,KAAK,EAAqB,IAAI,EAAwB,MAAM,mBAAmB,CAAC;AACvF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAIpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAOhE,QAAA,MAAM,sBAAsB;;;;;;;kBAiCf,CAAC;AAEd;;GAEG;AACH,wBAAgB,qBAAqB,CACjC,oBAAoB,EAAE,uBAAuB,EAC7C,gBAAgB,EAAE,gBAAgB,GACnC,IAAI,CAAC,OAAO,sBAAsB,CAAC,CA8GrC"}
|
|
@@ -24,7 +24,7 @@ const GrepContentInputSchema = z.object({
|
|
|
24
24
|
case_insensitive: z.boolean().optional().default(false).describe("Perform case-insensitive search (default: false)"),
|
|
25
25
|
max_results: z.number().int().positive().optional().default(100).describe("Maximum number of results to return (default: 100)")
|
|
26
26
|
}).strict();
|
|
27
|
-
function createGrepContentTool(getFileSystemService) {
|
|
27
|
+
function createGrepContentTool(getFileSystemService, blockedPathCheck) {
|
|
28
28
|
return defineTool({
|
|
29
29
|
id: "grep_content",
|
|
30
30
|
aliases: ["grep"],
|
|
@@ -83,6 +83,9 @@ function createGrepContentTool(getFileSystemService) {
|
|
|
83
83
|
const matches = [];
|
|
84
84
|
let filesSearched = 0;
|
|
85
85
|
for (const file of files) {
|
|
86
|
+
if (await blockedPathCheck(handle.context.path, file, context.logger) !== null) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
86
89
|
let content;
|
|
87
90
|
try {
|
|
88
91
|
content = await handle.files.readText(file);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var import_vitest = require("vitest");
|
|
3
|
+
var import_test_helpers = require("./test-helpers.js");
|
|
3
4
|
var import_core = require("@dexto/core");
|
|
4
5
|
var import_workspace = require("@dexto/core/workspace");
|
|
5
6
|
var import_grep_content_tool = require("./grep-content-tool.js");
|
|
@@ -67,7 +68,7 @@ function readTestFile(filesByPath, filePath) {
|
|
|
67
68
|
throw new Error("grep_content execute must not use FileSystemService");
|
|
68
69
|
});
|
|
69
70
|
const glob = import_vitest.vi.fn(async () => ["src/notes.txt"]);
|
|
70
|
-
const tool = (0, import_grep_content_tool.createGrepContentTool)(getFileSystemService);
|
|
71
|
+
const tool = (0, import_grep_content_tool.createGrepContentTool)(getFileSystemService, import_test_helpers.allowAllPaths);
|
|
71
72
|
const parsedInput = tool.inputSchema.parse({
|
|
72
73
|
pattern: "needle",
|
|
73
74
|
path: "src",
|
|
@@ -96,7 +97,7 @@ function readTestFile(filesByPath, filePath) {
|
|
|
96
97
|
(0, import_vitest.it)("normalizes workspace-contained absolute search paths before globbing", async () => {
|
|
97
98
|
const mockLogger = createMockLogger();
|
|
98
99
|
const glob = import_vitest.vi.fn(async () => ["src/notes.txt"]);
|
|
99
|
-
const tool = (0, import_grep_content_tool.createGrepContentTool)(import_vitest.vi.fn());
|
|
100
|
+
const tool = (0, import_grep_content_tool.createGrepContentTool)(import_vitest.vi.fn(), import_test_helpers.allowAllPaths);
|
|
100
101
|
await tool.execute(
|
|
101
102
|
tool.inputSchema.parse({
|
|
102
103
|
pattern: "needle",
|
|
@@ -110,7 +111,7 @@ function readTestFile(filesByPath, filePath) {
|
|
|
110
111
|
(0, import_vitest.it)("rejects external absolute search paths before file provider calls", async () => {
|
|
111
112
|
const mockLogger = createMockLogger();
|
|
112
113
|
const glob = import_vitest.vi.fn(async () => ["src/notes.txt"]);
|
|
113
|
-
const tool = (0, import_grep_content_tool.createGrepContentTool)(import_vitest.vi.fn());
|
|
114
|
+
const tool = (0, import_grep_content_tool.createGrepContentTool)(import_vitest.vi.fn(), import_test_helpers.allowAllPaths);
|
|
114
115
|
await (0, import_vitest.expect)(
|
|
115
116
|
tool.execute(
|
|
116
117
|
tool.inputSchema.parse({
|
|
@@ -126,7 +127,7 @@ function readTestFile(filesByPath, filePath) {
|
|
|
126
127
|
(0, import_vitest.it)("rejects absolute and escaping glob filters before file provider calls", async () => {
|
|
127
128
|
const mockLogger = createMockLogger();
|
|
128
129
|
const glob = import_vitest.vi.fn(async () => ["src/notes.txt"]);
|
|
129
|
-
const tool = (0, import_grep_content_tool.createGrepContentTool)(import_vitest.vi.fn());
|
|
130
|
+
const tool = (0, import_grep_content_tool.createGrepContentTool)(import_vitest.vi.fn(), import_test_helpers.allowAllPaths);
|
|
130
131
|
await (0, import_vitest.expect)(
|
|
131
132
|
tool.execute(
|
|
132
133
|
tool.inputSchema.parse({
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { allowAllPaths } from "./test-helpers.js";
|
|
2
3
|
import { ToolErrorCode } from "@dexto/core";
|
|
3
4
|
import { WorkspaceError } from "@dexto/core/workspace";
|
|
4
5
|
import { createGrepContentTool } from "./grep-content-tool.js";
|
|
@@ -66,7 +67,7 @@ describe("grep_content tool", () => {
|
|
|
66
67
|
throw new Error("grep_content execute must not use FileSystemService");
|
|
67
68
|
});
|
|
68
69
|
const glob = vi.fn(async () => ["src/notes.txt"]);
|
|
69
|
-
const tool = createGrepContentTool(getFileSystemService);
|
|
70
|
+
const tool = createGrepContentTool(getFileSystemService, allowAllPaths);
|
|
70
71
|
const parsedInput = tool.inputSchema.parse({
|
|
71
72
|
pattern: "needle",
|
|
72
73
|
path: "src",
|
|
@@ -95,7 +96,7 @@ describe("grep_content tool", () => {
|
|
|
95
96
|
it("normalizes workspace-contained absolute search paths before globbing", async () => {
|
|
96
97
|
const mockLogger = createMockLogger();
|
|
97
98
|
const glob = vi.fn(async () => ["src/notes.txt"]);
|
|
98
|
-
const tool = createGrepContentTool(vi.fn());
|
|
99
|
+
const tool = createGrepContentTool(vi.fn(), allowAllPaths);
|
|
99
100
|
await tool.execute(
|
|
100
101
|
tool.inputSchema.parse({
|
|
101
102
|
pattern: "needle",
|
|
@@ -109,7 +110,7 @@ describe("grep_content tool", () => {
|
|
|
109
110
|
it("rejects external absolute search paths before file provider calls", async () => {
|
|
110
111
|
const mockLogger = createMockLogger();
|
|
111
112
|
const glob = vi.fn(async () => ["src/notes.txt"]);
|
|
112
|
-
const tool = createGrepContentTool(vi.fn());
|
|
113
|
+
const tool = createGrepContentTool(vi.fn(), allowAllPaths);
|
|
113
114
|
await expect(
|
|
114
115
|
tool.execute(
|
|
115
116
|
tool.inputSchema.parse({
|
|
@@ -125,7 +126,7 @@ describe("grep_content tool", () => {
|
|
|
125
126
|
it("rejects absolute and escaping glob filters before file provider calls", async () => {
|
|
126
127
|
const mockLogger = createMockLogger();
|
|
127
128
|
const glob = vi.fn(async () => ["src/notes.txt"]);
|
|
128
|
-
const tool = createGrepContentTool(vi.fn());
|
|
129
|
+
const tool = createGrepContentTool(vi.fn(), allowAllPaths);
|
|
129
130
|
await expect(
|
|
130
131
|
tool.execute(
|
|
131
132
|
tool.inputSchema.parse({
|
package/dist/index.d.cts
CHANGED
|
@@ -740,6 +740,13 @@ declare enum FileSystemErrorCode {
|
|
|
740
740
|
SERVICE_NOT_INITIALIZED = "FILESYSTEM_SERVICE_NOT_INITIALIZED"
|
|
741
741
|
}
|
|
742
742
|
|
|
743
|
+
/**
|
|
744
|
+
* Returns the reason a workspace path is blocked by the configured blocked paths and blocked
|
|
745
|
+
* extensions, or null when it is not blocked. Relative blocked paths resolve against the
|
|
746
|
+
* workspace root.
|
|
747
|
+
*/
|
|
748
|
+
type BlockedPathCheck = (workspaceRoot: string, workspacePath: string, logger: Logger) => Promise<string | null>;
|
|
749
|
+
|
|
743
750
|
/**
|
|
744
751
|
* Read File Tool
|
|
745
752
|
*
|
|
@@ -754,7 +761,7 @@ declare const ReadFileInputSchema: z.ZodObject<{
|
|
|
754
761
|
/**
|
|
755
762
|
* Create the read_file internal tool with directory approval support
|
|
756
763
|
*/
|
|
757
|
-
declare function createReadFileTool(getFileSystemService: FileSystemServiceGetter): Tool<typeof ReadFileInputSchema>;
|
|
764
|
+
declare function createReadFileTool(getFileSystemService: FileSystemServiceGetter, blockedPathCheck: BlockedPathCheck, maxFileSize: number): Tool<typeof ReadFileInputSchema>;
|
|
758
765
|
|
|
759
766
|
/**
|
|
760
767
|
* Read Media File Tool
|
|
@@ -786,7 +793,7 @@ declare const WriteFileInputSchema: z.ZodObject<{
|
|
|
786
793
|
/**
|
|
787
794
|
* Create the write_file internal tool with directory approval support
|
|
788
795
|
*/
|
|
789
|
-
declare function createWriteFileTool(getFileSystemService: FileSystemServiceGetter): Tool<typeof WriteFileInputSchema>;
|
|
796
|
+
declare function createWriteFileTool(getFileSystemService: FileSystemServiceGetter, blockedPathCheck: BlockedPathCheck): Tool<typeof WriteFileInputSchema>;
|
|
790
797
|
|
|
791
798
|
/**
|
|
792
799
|
* Edit File Tool
|
|
@@ -803,7 +810,7 @@ declare const EditFileInputSchema: z.ZodObject<{
|
|
|
803
810
|
/**
|
|
804
811
|
* Create the edit_file internal tool with directory approval support
|
|
805
812
|
*/
|
|
806
|
-
declare function createEditFileTool(getFileSystemService: FileSystemServiceGetter): Tool<typeof EditFileInputSchema>;
|
|
813
|
+
declare function createEditFileTool(getFileSystemService: FileSystemServiceGetter, blockedPathCheck: BlockedPathCheck, maxFileSize: number): Tool<typeof EditFileInputSchema>;
|
|
807
814
|
|
|
808
815
|
/**
|
|
809
816
|
* Glob Files Tool
|
|
@@ -819,7 +826,7 @@ declare const GlobFilesInputSchema: z.ZodObject<{
|
|
|
819
826
|
/**
|
|
820
827
|
* Create the glob_files internal tool with directory approval support
|
|
821
828
|
*/
|
|
822
|
-
declare function createGlobFilesTool(getFileSystemService: FileSystemServiceGetter): Tool<typeof GlobFilesInputSchema>;
|
|
829
|
+
declare function createGlobFilesTool(getFileSystemService: FileSystemServiceGetter, blockedPathCheck: BlockedPathCheck): Tool<typeof GlobFilesInputSchema>;
|
|
823
830
|
|
|
824
831
|
/**
|
|
825
832
|
* Grep Content Tool
|
|
@@ -838,6 +845,6 @@ declare const GrepContentInputSchema: z.ZodObject<{
|
|
|
838
845
|
/**
|
|
839
846
|
* Create the grep_content internal tool with directory approval support
|
|
840
847
|
*/
|
|
841
|
-
declare function createGrepContentTool(getFileSystemService: FileSystemServiceGetter): Tool<typeof GrepContentInputSchema>;
|
|
848
|
+
declare function createGrepContentTool(getFileSystemService: FileSystemServiceGetter, blockedPathCheck: BlockedPathCheck): Tool<typeof GrepContentInputSchema>;
|
|
842
849
|
|
|
843
850
|
export { type BufferEncoding, type CreateDirectoryOptions, type CreateDirectoryResult, type DeletePathOptions, type DeletePathResult, type DirectoryEntry, type EditFileOptions, type EditOperation, type EditResult, type FileContent, type FileMetadata, type FileSystemConfig, FileSystemError, FileSystemErrorCode, FileSystemService, type FileSystemServiceGetter, type FileSystemToolsConfig, FileSystemToolsConfigSchema, type GlobOptions, type GlobResult, type GrepOptions, type ListDirectoryOptions, type ListDirectoryResult, type MediaFileContent, type PathValidation, PathValidator, type ReadFileOptions, type RenamePathResult, type SearchMatch, type SearchResult, type WriteFileOptions, type WriteResult, createEditFileTool, createGlobFilesTool, createGrepContentTool, createReadFileTool, createReadMediaFileTool, createWriteFileTool, fileSystemToolsFactory };
|
package/dist/path-validator.cjs
CHANGED
|
@@ -194,11 +194,25 @@ class PathValidator {
|
|
|
194
194
|
* Check if path matches blocked patterns (blacklist check)
|
|
195
195
|
*/
|
|
196
196
|
isPathBlocked(normalizedPath) {
|
|
197
|
+
const lowerPath = normalizedPath.toLowerCase();
|
|
197
198
|
for (const { blocked, fullPath } of this.resolvedBlockedPaths) {
|
|
198
|
-
|
|
199
|
+
const lowerFullPath = fullPath.toLowerCase();
|
|
200
|
+
if (lowerPath === lowerFullPath || lowerPath.startsWith(lowerFullPath + path.sep)) {
|
|
199
201
|
return `Within blocked directory: ${blocked}`;
|
|
200
202
|
}
|
|
201
203
|
}
|
|
204
|
+
const roots = this.normalizedAllowedPaths.length > 0 ? [...this.normalizedAllowedPaths, ...this.canonicalAllowedPaths] : [(0, import_path_utils.resolveUserPath)(process.cwd(), this.config.workingDirectory || process.cwd())];
|
|
205
|
+
for (const root of roots) {
|
|
206
|
+
if (!isWithinRoot(root, normalizedPath)) continue;
|
|
207
|
+
const pathSegments = path.relative(root, normalizedPath).split(path.sep);
|
|
208
|
+
for (const blocked of this.normalizedBlockedPaths) {
|
|
209
|
+
if (path.isAbsolute(blocked)) continue;
|
|
210
|
+
const blockedSegments = blocked.split(path.sep).filter((s) => s !== "");
|
|
211
|
+
if (containsSegments(pathSegments, blockedSegments)) {
|
|
212
|
+
return `Within blocked directory: ${blocked}`;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
202
216
|
return null;
|
|
203
217
|
}
|
|
204
218
|
/**
|
|
@@ -330,6 +344,17 @@ class PathValidator {
|
|
|
330
344
|
return [...this.normalizedBlockedPaths];
|
|
331
345
|
}
|
|
332
346
|
}
|
|
347
|
+
function containsSegments(segments, needle) {
|
|
348
|
+
if (needle.length === 0) return false;
|
|
349
|
+
for (let start = 0; start + needle.length <= segments.length; start += 1) {
|
|
350
|
+
if (needle.every(
|
|
351
|
+
(segment, offset) => segments[start + offset]?.toLowerCase() === segment.toLowerCase()
|
|
352
|
+
)) {
|
|
353
|
+
return true;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
333
358
|
function isWithinRoot(root, candidate) {
|
|
334
359
|
const relative = path.relative(root, candidate);
|
|
335
360
|
if (relative === "") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path-validator.d.ts","sourceRoot":"","sources":["../src/path-validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAIjD;;;GAGG;AACH,MAAM,MAAM,0BAA0B,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AACnE,MAAM,MAAM,wBAAwB,GAAG,CACnC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,0BAA0B,KACpC,OAAO,CAAC;AAEb;;;;;;;;;;;;GAYG;AACH,qBAAa,aAAa;IACtB,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,sBAAsB,CAAW;IACzC,uFAAuF;IACvF,OAAO,CAAC,qBAAqB,CAAgB;IAC7C,2EAA2E;IAC3E,OAAO,CAAC,oBAAoB,CAAoD;IAChF,OAAO,CAAC,mBAAmB,CAA4B;IACvD,OAAO,CAAC,sBAAsB,CAAW;IACzC,OAAO,CAAC,2BAA2B,CAAW;IAC9C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,wBAAwB,CAAuC;gBAE3D,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM;IA4BpD;;;;;OAKG;IACH,2BAA2B,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI;IAKpE;;OAEG;IACG,YAAY,CACd,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,0BAA0B,EACrC,OAAO,GAAE;QAAE,kBAAkB,CAAC,EAAE,OAAO,CAAA;KAAO,GAC/C,OAAO,CAAC,cAAc,CAAC;IAQ1B;;;;;;;;;;;OAWG;IACG,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;YAQzD,oBAAoB;IA8FlC;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAgBxB;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAIrB;;OAEG;IACH,OAAO,CAAC,aAAa;
|
|
1
|
+
{"version":3,"file":"path-validator.d.ts","sourceRoot":"","sources":["../src/path-validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAIjD;;;GAGG;AACH,MAAM,MAAM,0BAA0B,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AACnE,MAAM,MAAM,wBAAwB,GAAG,CACnC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,0BAA0B,KACpC,OAAO,CAAC;AAEb;;;;;;;;;;;;GAYG;AACH,qBAAa,aAAa;IACtB,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,sBAAsB,CAAW;IACzC,uFAAuF;IACvF,OAAO,CAAC,qBAAqB,CAAgB;IAC7C,2EAA2E;IAC3E,OAAO,CAAC,oBAAoB,CAAoD;IAChF,OAAO,CAAC,mBAAmB,CAA4B;IACvD,OAAO,CAAC,sBAAsB,CAAW;IACzC,OAAO,CAAC,2BAA2B,CAAW;IAC9C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,wBAAwB,CAAuC;gBAE3D,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM;IA4BpD;;;;;OAKG;IACH,2BAA2B,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI;IAKpE;;OAEG;IACG,YAAY,CACd,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,0BAA0B,EACrC,OAAO,GAAE;QAAE,kBAAkB,CAAC,EAAE,OAAO,CAAA;KAAO,GAC/C,OAAO,CAAC,cAAc,CAAC;IAQ1B;;;;;;;;;;;OAWG;IACG,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;YAQzD,oBAAoB;IA8FlC;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAgBxB;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAIrB;;OAEG;IACH,OAAO,CAAC,aAAa;IAiCrB;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAkB3B;;;OAGG;IACH,kBAAkB,CAAC,cAAc,EAAE,MAAM,EAAE,SAAS,EAAE,0BAA0B,GAAG,OAAO;IAM1F;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAqBzB;;;;;;;;;OASG;IACG,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAyB7D;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAW9B;;;;;;OAMG;IACH,OAAO,CAAC,oBAAoB;YAKd,qBAAqB;IA2BnC;;OAEG;IACH,eAAe,IAAI,MAAM,EAAE;IAI3B;;OAEG;IACH,eAAe,IAAI,MAAM,EAAE;CAG9B"}
|
package/dist/path-validator.js
CHANGED
|
@@ -161,11 +161,25 @@ class PathValidator {
|
|
|
161
161
|
* Check if path matches blocked patterns (blacklist check)
|
|
162
162
|
*/
|
|
163
163
|
isPathBlocked(normalizedPath) {
|
|
164
|
+
const lowerPath = normalizedPath.toLowerCase();
|
|
164
165
|
for (const { blocked, fullPath } of this.resolvedBlockedPaths) {
|
|
165
|
-
|
|
166
|
+
const lowerFullPath = fullPath.toLowerCase();
|
|
167
|
+
if (lowerPath === lowerFullPath || lowerPath.startsWith(lowerFullPath + path.sep)) {
|
|
166
168
|
return `Within blocked directory: ${blocked}`;
|
|
167
169
|
}
|
|
168
170
|
}
|
|
171
|
+
const roots = this.normalizedAllowedPaths.length > 0 ? [...this.normalizedAllowedPaths, ...this.canonicalAllowedPaths] : [resolveUserPath(process.cwd(), this.config.workingDirectory || process.cwd())];
|
|
172
|
+
for (const root of roots) {
|
|
173
|
+
if (!isWithinRoot(root, normalizedPath)) continue;
|
|
174
|
+
const pathSegments = path.relative(root, normalizedPath).split(path.sep);
|
|
175
|
+
for (const blocked of this.normalizedBlockedPaths) {
|
|
176
|
+
if (path.isAbsolute(blocked)) continue;
|
|
177
|
+
const blockedSegments = blocked.split(path.sep).filter((s) => s !== "");
|
|
178
|
+
if (containsSegments(pathSegments, blockedSegments)) {
|
|
179
|
+
return `Within blocked directory: ${blocked}`;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
169
183
|
return null;
|
|
170
184
|
}
|
|
171
185
|
/**
|
|
@@ -297,6 +311,17 @@ class PathValidator {
|
|
|
297
311
|
return [...this.normalizedBlockedPaths];
|
|
298
312
|
}
|
|
299
313
|
}
|
|
314
|
+
function containsSegments(segments, needle) {
|
|
315
|
+
if (needle.length === 0) return false;
|
|
316
|
+
for (let start = 0; start + needle.length <= segments.length; start += 1) {
|
|
317
|
+
if (needle.every(
|
|
318
|
+
(segment, offset) => segments[start + offset]?.toLowerCase() === segment.toLowerCase()
|
|
319
|
+
)) {
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
300
325
|
function isWithinRoot(root, candidate) {
|
|
301
326
|
const relative = path.relative(root, candidate);
|
|
302
327
|
if (relative === "") {
|
|
@@ -226,6 +226,81 @@ const createMockLogger = () => ({
|
|
|
226
226
|
(0, import_vitest.expect)(result.isValid).toBe(false);
|
|
227
227
|
(0, import_vitest.expect)(result.error).toContain("blocked");
|
|
228
228
|
});
|
|
229
|
+
(0, import_vitest.describe)("nested entries", () => {
|
|
230
|
+
const validator = () => new import_path_validator.PathValidator(
|
|
231
|
+
{
|
|
232
|
+
allowedPaths: ["/home/user/project"],
|
|
233
|
+
blockedPaths: [".git", ".env", "node_modules/.bin"],
|
|
234
|
+
blockedExtensions: [],
|
|
235
|
+
maxFileSize: 10 * 1024 * 1024,
|
|
236
|
+
enableBackups: false,
|
|
237
|
+
backupRetentionDays: 7,
|
|
238
|
+
workingDirectory: "/home/user/project"
|
|
239
|
+
},
|
|
240
|
+
mockLogger
|
|
241
|
+
);
|
|
242
|
+
import_vitest.it.each([
|
|
243
|
+
"sub/.env",
|
|
244
|
+
"a/b/c/.env",
|
|
245
|
+
"sub/.git/config",
|
|
246
|
+
"packages/app/.git",
|
|
247
|
+
"packages/app/node_modules/.bin/tsc",
|
|
248
|
+
// Names differ only in case, as on a case-insensitive file system.
|
|
249
|
+
".ENV",
|
|
250
|
+
".Env",
|
|
251
|
+
"sub/.ENV",
|
|
252
|
+
"Sub/.Git/config",
|
|
253
|
+
".GIT/config",
|
|
254
|
+
"NODE_MODULES/.bin/tsc",
|
|
255
|
+
"packages/app/Node_Modules/.BIN/tsc"
|
|
256
|
+
])("rejects %s below the workspace root", async (relativePath) => {
|
|
257
|
+
const result = await validator().validatePath(
|
|
258
|
+
`/home/user/project/${relativePath}`,
|
|
259
|
+
"read"
|
|
260
|
+
);
|
|
261
|
+
(0, import_vitest.expect)(result.isValid).toBe(false);
|
|
262
|
+
(0, import_vitest.expect)(result.error).toContain("blocked");
|
|
263
|
+
});
|
|
264
|
+
import_vitest.it.each([
|
|
265
|
+
"sub/.envrc",
|
|
266
|
+
"sub/environment.ts",
|
|
267
|
+
"sub/my.git/config",
|
|
268
|
+
"node_modules/x"
|
|
269
|
+
])("still allows %s", async (relativePath) => {
|
|
270
|
+
const result = await validator().validatePath(
|
|
271
|
+
`/home/user/project/${relativePath}`,
|
|
272
|
+
"read"
|
|
273
|
+
);
|
|
274
|
+
(0, import_vitest.expect)(result.isValid).toBe(true);
|
|
275
|
+
});
|
|
276
|
+
(0, import_vitest.it)("matches an absolute blocked entry regardless of case", async () => {
|
|
277
|
+
const absoluteValidator = new import_path_validator.PathValidator(
|
|
278
|
+
{
|
|
279
|
+
allowedPaths: ["/home/user/project"],
|
|
280
|
+
blockedPaths: ["/home/user/project/private"],
|
|
281
|
+
blockedExtensions: [],
|
|
282
|
+
maxFileSize: 10 * 1024 * 1024,
|
|
283
|
+
enableBackups: false,
|
|
284
|
+
backupRetentionDays: 7,
|
|
285
|
+
workingDirectory: "/home/user/project"
|
|
286
|
+
},
|
|
287
|
+
mockLogger
|
|
288
|
+
);
|
|
289
|
+
for (const spelling of ["private/key", "PRIVATE/key", "Private"]) {
|
|
290
|
+
const result = await absoluteValidator.validatePath(
|
|
291
|
+
`/home/user/project/${spelling}`,
|
|
292
|
+
"read"
|
|
293
|
+
);
|
|
294
|
+
(0, import_vitest.expect)(result.isValid).toBe(false);
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
(0, import_vitest.it)("applies to previews of nested paths too", async () => {
|
|
298
|
+
const result = await validator().validatePathForPreview(
|
|
299
|
+
"/home/user/project/sub/.env"
|
|
300
|
+
);
|
|
301
|
+
(0, import_vitest.expect)(result.isValid).toBe(false);
|
|
302
|
+
});
|
|
303
|
+
});
|
|
229
304
|
});
|
|
230
305
|
(0, import_vitest.describe)("Blocked Extensions", () => {
|
|
231
306
|
(0, import_vitest.it)("should reject files with blocked extensions", async () => {
|
|
@@ -203,6 +203,81 @@ describe("PathValidator", () => {
|
|
|
203
203
|
expect(result.isValid).toBe(false);
|
|
204
204
|
expect(result.error).toContain("blocked");
|
|
205
205
|
});
|
|
206
|
+
describe("nested entries", () => {
|
|
207
|
+
const validator = () => new PathValidator(
|
|
208
|
+
{
|
|
209
|
+
allowedPaths: ["/home/user/project"],
|
|
210
|
+
blockedPaths: [".git", ".env", "node_modules/.bin"],
|
|
211
|
+
blockedExtensions: [],
|
|
212
|
+
maxFileSize: 10 * 1024 * 1024,
|
|
213
|
+
enableBackups: false,
|
|
214
|
+
backupRetentionDays: 7,
|
|
215
|
+
workingDirectory: "/home/user/project"
|
|
216
|
+
},
|
|
217
|
+
mockLogger
|
|
218
|
+
);
|
|
219
|
+
it.each([
|
|
220
|
+
"sub/.env",
|
|
221
|
+
"a/b/c/.env",
|
|
222
|
+
"sub/.git/config",
|
|
223
|
+
"packages/app/.git",
|
|
224
|
+
"packages/app/node_modules/.bin/tsc",
|
|
225
|
+
// Names differ only in case, as on a case-insensitive file system.
|
|
226
|
+
".ENV",
|
|
227
|
+
".Env",
|
|
228
|
+
"sub/.ENV",
|
|
229
|
+
"Sub/.Git/config",
|
|
230
|
+
".GIT/config",
|
|
231
|
+
"NODE_MODULES/.bin/tsc",
|
|
232
|
+
"packages/app/Node_Modules/.BIN/tsc"
|
|
233
|
+
])("rejects %s below the workspace root", async (relativePath) => {
|
|
234
|
+
const result = await validator().validatePath(
|
|
235
|
+
`/home/user/project/${relativePath}`,
|
|
236
|
+
"read"
|
|
237
|
+
);
|
|
238
|
+
expect(result.isValid).toBe(false);
|
|
239
|
+
expect(result.error).toContain("blocked");
|
|
240
|
+
});
|
|
241
|
+
it.each([
|
|
242
|
+
"sub/.envrc",
|
|
243
|
+
"sub/environment.ts",
|
|
244
|
+
"sub/my.git/config",
|
|
245
|
+
"node_modules/x"
|
|
246
|
+
])("still allows %s", async (relativePath) => {
|
|
247
|
+
const result = await validator().validatePath(
|
|
248
|
+
`/home/user/project/${relativePath}`,
|
|
249
|
+
"read"
|
|
250
|
+
);
|
|
251
|
+
expect(result.isValid).toBe(true);
|
|
252
|
+
});
|
|
253
|
+
it("matches an absolute blocked entry regardless of case", async () => {
|
|
254
|
+
const absoluteValidator = new PathValidator(
|
|
255
|
+
{
|
|
256
|
+
allowedPaths: ["/home/user/project"],
|
|
257
|
+
blockedPaths: ["/home/user/project/private"],
|
|
258
|
+
blockedExtensions: [],
|
|
259
|
+
maxFileSize: 10 * 1024 * 1024,
|
|
260
|
+
enableBackups: false,
|
|
261
|
+
backupRetentionDays: 7,
|
|
262
|
+
workingDirectory: "/home/user/project"
|
|
263
|
+
},
|
|
264
|
+
mockLogger
|
|
265
|
+
);
|
|
266
|
+
for (const spelling of ["private/key", "PRIVATE/key", "Private"]) {
|
|
267
|
+
const result = await absoluteValidator.validatePath(
|
|
268
|
+
`/home/user/project/${spelling}`,
|
|
269
|
+
"read"
|
|
270
|
+
);
|
|
271
|
+
expect(result.isValid).toBe(false);
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
it("applies to previews of nested paths too", async () => {
|
|
275
|
+
const result = await validator().validatePathForPreview(
|
|
276
|
+
"/home/user/project/sub/.env"
|
|
277
|
+
);
|
|
278
|
+
expect(result.isValid).toBe(false);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
206
281
|
});
|
|
207
282
|
describe("Blocked Extensions", () => {
|
|
208
283
|
it("should reject files with blocked extensions", async () => {
|
package/dist/read-file-tool.cjs
CHANGED
|
@@ -23,14 +23,16 @@ __export(read_file_tool_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(read_file_tool_exports);
|
|
24
24
|
var import_zod = require("zod");
|
|
25
25
|
var import_tools = require("@dexto/core/tools");
|
|
26
|
+
var import_file_size = require("./file-size.js");
|
|
26
27
|
var import_directory_approval = require("./directory-approval.js");
|
|
28
|
+
var import_blocked_path_check = require("./blocked-path-check.js");
|
|
27
29
|
var import_workspace_paths = require("./workspace-paths.js");
|
|
28
30
|
const ReadFileInputSchema = import_zod.z.object({
|
|
29
31
|
file_path: import_zod.z.string().min(1).describe("Absolute path to the file to read"),
|
|
30
32
|
limit: import_zod.z.number().int().positive().optional().describe("Maximum number of lines to read (optional)"),
|
|
31
33
|
offset: import_zod.z.number().int().min(1).optional().describe("Starting line number (1-based, optional)")
|
|
32
34
|
}).strict();
|
|
33
|
-
function createReadFileTool(getFileSystemService) {
|
|
35
|
+
function createReadFileTool(getFileSystemService, blockedPathCheck, maxFileSize) {
|
|
34
36
|
return (0, import_tools.defineTool)({
|
|
35
37
|
id: "read_file",
|
|
36
38
|
aliases: ["read"],
|
|
@@ -63,7 +65,17 @@ function createReadFileTool(getFileSystemService) {
|
|
|
63
65
|
handle.context.path,
|
|
64
66
|
input.file_path
|
|
65
67
|
);
|
|
66
|
-
|
|
68
|
+
await (0, import_blocked_path_check.assertPathNotBlocked)(
|
|
69
|
+
blockedPathCheck,
|
|
70
|
+
handle.context.path,
|
|
71
|
+
workspacePath,
|
|
72
|
+
context.logger
|
|
73
|
+
);
|
|
74
|
+
const content = await (0, import_file_size.readTextWithinMaxFileSize)(
|
|
75
|
+
handle.files,
|
|
76
|
+
workspacePath,
|
|
77
|
+
maxFileSize
|
|
78
|
+
);
|
|
67
79
|
const result = applyLineWindow(content, {
|
|
68
80
|
limit: input.limit,
|
|
69
81
|
offset: input.offset
|
package/dist/read-file-tool.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
import type { Tool } from '@dexto/core/tools';
|
|
8
8
|
import type { FileSystemServiceGetter } from './file-tool-types.js';
|
|
9
|
+
import { type BlockedPathCheck } from './blocked-path-check.js';
|
|
9
10
|
declare const ReadFileInputSchema: z.ZodObject<{
|
|
10
11
|
file_path: z.ZodString;
|
|
11
12
|
limit: z.ZodOptional<z.ZodNumber>;
|
|
@@ -14,6 +15,6 @@ declare const ReadFileInputSchema: z.ZodObject<{
|
|
|
14
15
|
/**
|
|
15
16
|
* Create the read_file internal tool with directory approval support
|
|
16
17
|
*/
|
|
17
|
-
export declare function createReadFileTool(getFileSystemService: FileSystemServiceGetter): Tool<typeof ReadFileInputSchema>;
|
|
18
|
+
export declare function createReadFileTool(getFileSystemService: FileSystemServiceGetter, blockedPathCheck: BlockedPathCheck, maxFileSize: number): Tool<typeof ReadFileInputSchema>;
|
|
18
19
|
export {};
|
|
19
20
|
//# sourceMappingURL=read-file-tool.d.ts.map
|
|
@@ -1 +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;AAOxB,OAAO,KAAK,EAAmB,IAAI,EAAwB,MAAM,mBAAmB,CAAC;AACrF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;
|
|
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;AAOxB,OAAO,KAAK,EAAmB,IAAI,EAAwB,MAAM,mBAAmB,CAAC;AACrF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAIpE,OAAO,EAAwB,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAGtF,QAAA,MAAM,mBAAmB;;;;kBAgBZ,CAAC;AAEd;;GAEG;AACH,wBAAgB,kBAAkB,CAC9B,oBAAoB,EAAE,uBAAuB,EAC7C,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,MAAM,GACpB,IAAI,CAAC,OAAO,mBAAmB,CAAC,CA2ElC"}
|