@dexto/tools-filesystem 1.16.5 → 1.17.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/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
package/dist/read-file-tool.js
CHANGED
|
@@ -5,14 +5,16 @@ import {
|
|
|
5
5
|
defineTool,
|
|
6
6
|
truncateForHeader
|
|
7
7
|
} from "@dexto/core/tools";
|
|
8
|
+
import { readTextWithinMaxFileSize } from "./file-size.js";
|
|
8
9
|
import { createDirectoryAccessApprovalHandlers, resolveFilePath } from "./directory-approval.js";
|
|
10
|
+
import { assertPathNotBlocked } from "./blocked-path-check.js";
|
|
9
11
|
import { toWorkspaceRelativePath } from "./workspace-paths.js";
|
|
10
12
|
const ReadFileInputSchema = z.object({
|
|
11
13
|
file_path: z.string().min(1).describe("Absolute path to the file to read"),
|
|
12
14
|
limit: z.number().int().positive().optional().describe("Maximum number of lines to read (optional)"),
|
|
13
15
|
offset: z.number().int().min(1).optional().describe("Starting line number (1-based, optional)")
|
|
14
16
|
}).strict();
|
|
15
|
-
function createReadFileTool(getFileSystemService) {
|
|
17
|
+
function createReadFileTool(getFileSystemService, blockedPathCheck, maxFileSize) {
|
|
16
18
|
return defineTool({
|
|
17
19
|
id: "read_file",
|
|
18
20
|
aliases: ["read"],
|
|
@@ -45,7 +47,17 @@ function createReadFileTool(getFileSystemService) {
|
|
|
45
47
|
handle.context.path,
|
|
46
48
|
input.file_path
|
|
47
49
|
);
|
|
48
|
-
|
|
50
|
+
await assertPathNotBlocked(
|
|
51
|
+
blockedPathCheck,
|
|
52
|
+
handle.context.path,
|
|
53
|
+
workspacePath,
|
|
54
|
+
context.logger
|
|
55
|
+
);
|
|
56
|
+
const content = await readTextWithinMaxFileSize(
|
|
57
|
+
handle.files,
|
|
58
|
+
workspacePath,
|
|
59
|
+
maxFileSize
|
|
60
|
+
);
|
|
49
61
|
const result = applyLineWindow(content, {
|
|
50
62
|
limit: input.limit,
|
|
51
63
|
offset: input.offset
|
|
@@ -25,8 +25,10 @@ var import_core = require("@dexto/core");
|
|
|
25
25
|
var import_storage = require("@dexto/core/storage");
|
|
26
26
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
27
27
|
var import_vitest = require("vitest");
|
|
28
|
+
var import_error_codes = require("./error-codes.js");
|
|
29
|
+
var import_test_helpers = require("./test-helpers.js");
|
|
28
30
|
var import_read_file_tool = require("./read-file-tool.js");
|
|
29
|
-
async function createContext(content, readText = import_vitest.vi.fn(async () => content)) {
|
|
31
|
+
async function createContext(content, readText = import_vitest.vi.fn(async () => content), readFileSize) {
|
|
30
32
|
const stores = new import_storage.InMemoryDextoStores();
|
|
31
33
|
await stores.connect();
|
|
32
34
|
const logger = (0, import_core.createLogger)({
|
|
@@ -44,6 +46,7 @@ async function createContext(content, readText = import_vitest.vi.fn(async () =>
|
|
|
44
46
|
files: {
|
|
45
47
|
readFile: import_vitest.vi.fn(async () => content),
|
|
46
48
|
readText,
|
|
49
|
+
...readFileSize === void 0 ? {} : { readFileSize },
|
|
47
50
|
glob: import_vitest.vi.fn(async () => []),
|
|
48
51
|
writeFile: import_vitest.vi.fn(async () => void 0),
|
|
49
52
|
listFiles: import_vitest.vi.fn(async () => [])
|
|
@@ -71,7 +74,7 @@ async function createContext(content, readText = import_vitest.vi.fn(async () =>
|
|
|
71
74
|
const getFileSystemService = import_vitest.vi.fn(async () => {
|
|
72
75
|
throw new Error("read_file execute must not use FileSystemService");
|
|
73
76
|
});
|
|
74
|
-
const tool = (0, import_read_file_tool.createReadFileTool)(getFileSystemService);
|
|
77
|
+
const tool = (0, import_read_file_tool.createReadFileTool)(getFileSystemService, import_test_helpers.allowAllPaths, 10 * 1024 * 1024);
|
|
75
78
|
const result = await tool.execute({ file_path: "local.txt" }, await createContext("alpha"));
|
|
76
79
|
(0, import_vitest.expect)(getFileSystemService).not.toHaveBeenCalled();
|
|
77
80
|
(0, import_vitest.expect)(result).toMatchObject({
|
|
@@ -83,7 +86,7 @@ async function createContext(content, readText = import_vitest.vi.fn(async () =>
|
|
|
83
86
|
});
|
|
84
87
|
});
|
|
85
88
|
(0, import_vitest.it)("applies pagination after workspace reads", async () => {
|
|
86
|
-
const tool = (0, import_read_file_tool.createReadFileTool)(import_vitest.vi.fn());
|
|
89
|
+
const tool = (0, import_read_file_tool.createReadFileTool)(import_vitest.vi.fn(), import_test_helpers.allowAllPaths, 10 * 1024 * 1024);
|
|
87
90
|
const result = await tool.execute(
|
|
88
91
|
{ file_path: "local.txt", offset: 2, limit: 2 },
|
|
89
92
|
await createContext("one\ntwo\nthree\nfour")
|
|
@@ -98,7 +101,7 @@ async function createContext(content, readText = import_vitest.vi.fn(async () =>
|
|
|
98
101
|
});
|
|
99
102
|
(0, import_vitest.it)("normalizes workspace-contained absolute paths before reading", async () => {
|
|
100
103
|
const readText = import_vitest.vi.fn(async () => "alpha");
|
|
101
|
-
const tool = (0, import_read_file_tool.createReadFileTool)(import_vitest.vi.fn());
|
|
104
|
+
const tool = (0, import_read_file_tool.createReadFileTool)(import_vitest.vi.fn(), import_test_helpers.allowAllPaths, 10 * 1024 * 1024);
|
|
102
105
|
await tool.execute(
|
|
103
106
|
{ file_path: import_node_path.default.join("/repo", "local.txt") },
|
|
104
107
|
await createContext("alpha", readText)
|
|
@@ -107,7 +110,7 @@ async function createContext(content, readText = import_vitest.vi.fn(async () =>
|
|
|
107
110
|
});
|
|
108
111
|
(0, import_vitest.it)("rejects external absolute paths before file provider calls", async () => {
|
|
109
112
|
const readText = import_vitest.vi.fn(async () => "alpha");
|
|
110
|
-
const tool = (0, import_read_file_tool.createReadFileTool)(import_vitest.vi.fn());
|
|
113
|
+
const tool = (0, import_read_file_tool.createReadFileTool)(import_vitest.vi.fn(), import_test_helpers.allowAllPaths, 10 * 1024 * 1024);
|
|
111
114
|
await (0, import_vitest.expect)(
|
|
112
115
|
tool.execute(
|
|
113
116
|
{ file_path: "/outside/local.txt" },
|
|
@@ -116,4 +119,50 @@ async function createContext(content, readText = import_vitest.vi.fn(async () =>
|
|
|
116
119
|
).rejects.toMatchObject({ code: import_core.ToolErrorCode.VALIDATION_FAILED });
|
|
117
120
|
(0, import_vitest.expect)(readText).not.toHaveBeenCalled();
|
|
118
121
|
});
|
|
122
|
+
(0, import_vitest.it)("refuses a file larger than maxFileSize", async () => {
|
|
123
|
+
const tool = (0, import_read_file_tool.createReadFileTool)(import_vitest.vi.fn(), import_test_helpers.allowAllPaths, 10);
|
|
124
|
+
await (0, import_vitest.expect)(
|
|
125
|
+
tool.execute({ file_path: "big.txt" }, await createContext("x".repeat(11)))
|
|
126
|
+
).rejects.toMatchObject({ code: import_error_codes.FileSystemErrorCode.FILE_TOO_LARGE });
|
|
127
|
+
});
|
|
128
|
+
(0, import_vitest.it)("counts bytes, not characters, against maxFileSize", async () => {
|
|
129
|
+
const tool = (0, import_read_file_tool.createReadFileTool)(import_vitest.vi.fn(), import_test_helpers.allowAllPaths, 10);
|
|
130
|
+
await (0, import_vitest.expect)(
|
|
131
|
+
tool.execute({ file_path: "wide.txt" }, await createContext("\xE9\xE9\xE9\xE9\xE9\xE9"))
|
|
132
|
+
).rejects.toMatchObject({ code: import_error_codes.FileSystemErrorCode.FILE_TOO_LARGE });
|
|
133
|
+
});
|
|
134
|
+
(0, import_vitest.it)("reads a file that is exactly maxFileSize", async () => {
|
|
135
|
+
const tool = (0, import_read_file_tool.createReadFileTool)(import_vitest.vi.fn(), import_test_helpers.allowAllPaths, 10);
|
|
136
|
+
await (0, import_vitest.expect)(
|
|
137
|
+
tool.execute({ file_path: "edge.txt" }, await createContext("x".repeat(10)))
|
|
138
|
+
).resolves.toMatchObject({ size: 10 });
|
|
139
|
+
});
|
|
140
|
+
(0, import_vitest.it)("checks the size before reading the file", async () => {
|
|
141
|
+
const readText = import_vitest.vi.fn(async () => "x".repeat(11));
|
|
142
|
+
const readFileSize = import_vitest.vi.fn(async () => 11);
|
|
143
|
+
const tool = (0, import_read_file_tool.createReadFileTool)(import_vitest.vi.fn(), import_test_helpers.allowAllPaths, 10);
|
|
144
|
+
await (0, import_vitest.expect)(
|
|
145
|
+
tool.execute({ file_path: "big.txt" }, await createContext("", readText, readFileSize))
|
|
146
|
+
).rejects.toMatchObject({ code: import_error_codes.FileSystemErrorCode.FILE_TOO_LARGE });
|
|
147
|
+
(0, import_vitest.expect)(readFileSize).toHaveBeenCalledWith("big.txt");
|
|
148
|
+
(0, import_vitest.expect)(readText).not.toHaveBeenCalled();
|
|
149
|
+
});
|
|
150
|
+
(0, import_vitest.it)("reads a file the handle reports at exactly maxFileSize", async () => {
|
|
151
|
+
const tool = (0, import_read_file_tool.createReadFileTool)(import_vitest.vi.fn(), import_test_helpers.allowAllPaths, 10);
|
|
152
|
+
await (0, import_vitest.expect)(
|
|
153
|
+
tool.execute(
|
|
154
|
+
{ file_path: "edge.txt" },
|
|
155
|
+
await createContext("x".repeat(10), void 0, async () => 10)
|
|
156
|
+
)
|
|
157
|
+
).resolves.toMatchObject({ size: 10 });
|
|
158
|
+
});
|
|
159
|
+
(0, import_vitest.it)("still checks after reading when the reported size was wrong", async () => {
|
|
160
|
+
const tool = (0, import_read_file_tool.createReadFileTool)(import_vitest.vi.fn(), import_test_helpers.allowAllPaths, 10);
|
|
161
|
+
await (0, import_vitest.expect)(
|
|
162
|
+
tool.execute(
|
|
163
|
+
{ file_path: "grew.txt" },
|
|
164
|
+
await createContext("x".repeat(11), void 0, async () => 3)
|
|
165
|
+
)
|
|
166
|
+
).rejects.toMatchObject({ code: import_error_codes.FileSystemErrorCode.FILE_TOO_LARGE });
|
|
167
|
+
});
|
|
119
168
|
});
|
|
@@ -2,8 +2,10 @@ import { AgentEventBus, createLogger, ToolErrorCode, WorkspaceManager } from "@d
|
|
|
2
2
|
import { InMemoryDextoStores } from "@dexto/core/storage";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { FileSystemErrorCode } from "./error-codes.js";
|
|
6
|
+
import { allowAllPaths } from "./test-helpers.js";
|
|
5
7
|
import { createReadFileTool } from "./read-file-tool.js";
|
|
6
|
-
async function createContext(content, readText = vi.fn(async () => content)) {
|
|
8
|
+
async function createContext(content, readText = vi.fn(async () => content), readFileSize) {
|
|
7
9
|
const stores = new InMemoryDextoStores();
|
|
8
10
|
await stores.connect();
|
|
9
11
|
const logger = createLogger({
|
|
@@ -21,6 +23,7 @@ async function createContext(content, readText = vi.fn(async () => content)) {
|
|
|
21
23
|
files: {
|
|
22
24
|
readFile: vi.fn(async () => content),
|
|
23
25
|
readText,
|
|
26
|
+
...readFileSize === void 0 ? {} : { readFileSize },
|
|
24
27
|
glob: vi.fn(async () => []),
|
|
25
28
|
writeFile: vi.fn(async () => void 0),
|
|
26
29
|
listFiles: vi.fn(async () => [])
|
|
@@ -48,7 +51,7 @@ describe("read_file tool", () => {
|
|
|
48
51
|
const getFileSystemService = vi.fn(async () => {
|
|
49
52
|
throw new Error("read_file execute must not use FileSystemService");
|
|
50
53
|
});
|
|
51
|
-
const tool = createReadFileTool(getFileSystemService);
|
|
54
|
+
const tool = createReadFileTool(getFileSystemService, allowAllPaths, 10 * 1024 * 1024);
|
|
52
55
|
const result = await tool.execute({ file_path: "local.txt" }, await createContext("alpha"));
|
|
53
56
|
expect(getFileSystemService).not.toHaveBeenCalled();
|
|
54
57
|
expect(result).toMatchObject({
|
|
@@ -60,7 +63,7 @@ describe("read_file tool", () => {
|
|
|
60
63
|
});
|
|
61
64
|
});
|
|
62
65
|
it("applies pagination after workspace reads", async () => {
|
|
63
|
-
const tool = createReadFileTool(vi.fn());
|
|
66
|
+
const tool = createReadFileTool(vi.fn(), allowAllPaths, 10 * 1024 * 1024);
|
|
64
67
|
const result = await tool.execute(
|
|
65
68
|
{ file_path: "local.txt", offset: 2, limit: 2 },
|
|
66
69
|
await createContext("one\ntwo\nthree\nfour")
|
|
@@ -75,7 +78,7 @@ describe("read_file tool", () => {
|
|
|
75
78
|
});
|
|
76
79
|
it("normalizes workspace-contained absolute paths before reading", async () => {
|
|
77
80
|
const readText = vi.fn(async () => "alpha");
|
|
78
|
-
const tool = createReadFileTool(vi.fn());
|
|
81
|
+
const tool = createReadFileTool(vi.fn(), allowAllPaths, 10 * 1024 * 1024);
|
|
79
82
|
await tool.execute(
|
|
80
83
|
{ file_path: path.join("/repo", "local.txt") },
|
|
81
84
|
await createContext("alpha", readText)
|
|
@@ -84,7 +87,7 @@ describe("read_file tool", () => {
|
|
|
84
87
|
});
|
|
85
88
|
it("rejects external absolute paths before file provider calls", async () => {
|
|
86
89
|
const readText = vi.fn(async () => "alpha");
|
|
87
|
-
const tool = createReadFileTool(vi.fn());
|
|
90
|
+
const tool = createReadFileTool(vi.fn(), allowAllPaths, 10 * 1024 * 1024);
|
|
88
91
|
await expect(
|
|
89
92
|
tool.execute(
|
|
90
93
|
{ file_path: "/outside/local.txt" },
|
|
@@ -93,4 +96,50 @@ describe("read_file tool", () => {
|
|
|
93
96
|
).rejects.toMatchObject({ code: ToolErrorCode.VALIDATION_FAILED });
|
|
94
97
|
expect(readText).not.toHaveBeenCalled();
|
|
95
98
|
});
|
|
99
|
+
it("refuses a file larger than maxFileSize", async () => {
|
|
100
|
+
const tool = createReadFileTool(vi.fn(), allowAllPaths, 10);
|
|
101
|
+
await expect(
|
|
102
|
+
tool.execute({ file_path: "big.txt" }, await createContext("x".repeat(11)))
|
|
103
|
+
).rejects.toMatchObject({ code: FileSystemErrorCode.FILE_TOO_LARGE });
|
|
104
|
+
});
|
|
105
|
+
it("counts bytes, not characters, against maxFileSize", async () => {
|
|
106
|
+
const tool = createReadFileTool(vi.fn(), allowAllPaths, 10);
|
|
107
|
+
await expect(
|
|
108
|
+
tool.execute({ file_path: "wide.txt" }, await createContext("\xE9\xE9\xE9\xE9\xE9\xE9"))
|
|
109
|
+
).rejects.toMatchObject({ code: FileSystemErrorCode.FILE_TOO_LARGE });
|
|
110
|
+
});
|
|
111
|
+
it("reads a file that is exactly maxFileSize", async () => {
|
|
112
|
+
const tool = createReadFileTool(vi.fn(), allowAllPaths, 10);
|
|
113
|
+
await expect(
|
|
114
|
+
tool.execute({ file_path: "edge.txt" }, await createContext("x".repeat(10)))
|
|
115
|
+
).resolves.toMatchObject({ size: 10 });
|
|
116
|
+
});
|
|
117
|
+
it("checks the size before reading the file", async () => {
|
|
118
|
+
const readText = vi.fn(async () => "x".repeat(11));
|
|
119
|
+
const readFileSize = vi.fn(async () => 11);
|
|
120
|
+
const tool = createReadFileTool(vi.fn(), allowAllPaths, 10);
|
|
121
|
+
await expect(
|
|
122
|
+
tool.execute({ file_path: "big.txt" }, await createContext("", readText, readFileSize))
|
|
123
|
+
).rejects.toMatchObject({ code: FileSystemErrorCode.FILE_TOO_LARGE });
|
|
124
|
+
expect(readFileSize).toHaveBeenCalledWith("big.txt");
|
|
125
|
+
expect(readText).not.toHaveBeenCalled();
|
|
126
|
+
});
|
|
127
|
+
it("reads a file the handle reports at exactly maxFileSize", async () => {
|
|
128
|
+
const tool = createReadFileTool(vi.fn(), allowAllPaths, 10);
|
|
129
|
+
await expect(
|
|
130
|
+
tool.execute(
|
|
131
|
+
{ file_path: "edge.txt" },
|
|
132
|
+
await createContext("x".repeat(10), void 0, async () => 10)
|
|
133
|
+
)
|
|
134
|
+
).resolves.toMatchObject({ size: 10 });
|
|
135
|
+
});
|
|
136
|
+
it("still checks after reading when the reported size was wrong", async () => {
|
|
137
|
+
const tool = createReadFileTool(vi.fn(), allowAllPaths, 10);
|
|
138
|
+
await expect(
|
|
139
|
+
tool.execute(
|
|
140
|
+
{ file_path: "grew.txt" },
|
|
141
|
+
await createContext("x".repeat(11), void 0, async () => 3)
|
|
142
|
+
)
|
|
143
|
+
).rejects.toMatchObject({ code: FileSystemErrorCode.FILE_TOO_LARGE });
|
|
144
|
+
});
|
|
96
145
|
});
|
|
@@ -0,0 +1,28 @@
|
|
|
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 test_helpers_exports = {};
|
|
20
|
+
__export(test_helpers_exports, {
|
|
21
|
+
allowAllPaths: () => allowAllPaths
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(test_helpers_exports);
|
|
24
|
+
const allowAllPaths = async () => null;
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
allowAllPaths
|
|
28
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-helpers.d.ts","sourceRoot":"","sources":["../src/test-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,uFAAuF;AACvF,eAAO,MAAM,aAAa,EAAE,gBAAmC,CAAC"}
|
|
@@ -33,12 +33,12 @@ export declare const FileSystemToolsConfigSchema: z.ZodObject<{
|
|
|
33
33
|
backupPath: z.ZodOptional<z.ZodString>;
|
|
34
34
|
backupRetentionDays: z.ZodDefault<z.ZodNumber>;
|
|
35
35
|
enabledTools: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
36
|
+
edit_file: "edit_file";
|
|
37
|
+
grep_content: "grep_content";
|
|
36
38
|
read_file: "read_file";
|
|
37
39
|
write_file: "write_file";
|
|
38
|
-
edit_file: "edit_file";
|
|
39
40
|
read_media_file: "read_media_file";
|
|
40
41
|
glob_files: "glob_files";
|
|
41
|
-
grep_content: "grep_content";
|
|
42
42
|
}>>>;
|
|
43
43
|
}, z.core.$strict>;
|
|
44
44
|
export type FileSystemToolsConfig = z.output<typeof FileSystemToolsConfigSchema>;
|
package/dist/tool-factory.cjs
CHANGED
|
@@ -28,6 +28,7 @@ var import_read_media_file_tool = require("./read-media-file-tool.js");
|
|
|
28
28
|
var import_write_file_tool = require("./write-file-tool.js");
|
|
29
29
|
var import_edit_file_tool = require("./edit-file-tool.js");
|
|
30
30
|
var import_glob_files_tool = require("./glob-files-tool.js");
|
|
31
|
+
var import_blocked_path_check = require("./blocked-path-check.js");
|
|
31
32
|
var import_grep_content_tool = require("./grep-content-tool.js");
|
|
32
33
|
var import_directory_approval = require("./directory-approval.js");
|
|
33
34
|
var import_tool_factory_config = require("./tool-factory-config.js");
|
|
@@ -92,13 +93,16 @@ const fileSystemToolsFactory = {
|
|
|
92
93
|
await scopedFileSystemService.initialize();
|
|
93
94
|
return scopedFileSystemService;
|
|
94
95
|
};
|
|
96
|
+
const blockedPathCheck = (0, import_blocked_path_check.createBlockedPathCheck)({
|
|
97
|
+
...fileSystemConfig
|
|
98
|
+
});
|
|
95
99
|
const toolCreators = {
|
|
96
|
-
read_file: () => (0, import_read_file_tool.createReadFileTool)(getFileSystemService),
|
|
100
|
+
read_file: () => (0, import_read_file_tool.createReadFileTool)(getFileSystemService, blockedPathCheck, config.maxFileSize),
|
|
97
101
|
read_media_file: () => (0, import_read_media_file_tool.createReadMediaFileTool)(getFileSystemService),
|
|
98
|
-
write_file: () => (0, import_write_file_tool.createWriteFileTool)(getFileSystemService),
|
|
99
|
-
edit_file: () => (0, import_edit_file_tool.createEditFileTool)(getFileSystemService),
|
|
100
|
-
glob_files: () => (0, import_glob_files_tool.createGlobFilesTool)(getFileSystemService),
|
|
101
|
-
grep_content: () => (0, import_grep_content_tool.createGrepContentTool)(getFileSystemService)
|
|
102
|
+
write_file: () => (0, import_write_file_tool.createWriteFileTool)(getFileSystemService, blockedPathCheck),
|
|
103
|
+
edit_file: () => (0, import_edit_file_tool.createEditFileTool)(getFileSystemService, blockedPathCheck, config.maxFileSize),
|
|
104
|
+
glob_files: () => (0, import_glob_files_tool.createGlobFilesTool)(getFileSystemService, blockedPathCheck),
|
|
105
|
+
grep_content: () => (0, import_grep_content_tool.createGrepContentTool)(getFileSystemService, blockedPathCheck)
|
|
102
106
|
};
|
|
103
107
|
const toolsToCreate = config.enabledTools ?? import_tool_factory_config.FILESYSTEM_TOOL_NAMES;
|
|
104
108
|
return toolsToCreate.map((toolName) => toolCreators[toolName]());
|
|
@@ -1 +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;
|
|
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;AAavD,OAAO,EAGH,KAAK,qBAAqB,EAC7B,MAAM,0BAA0B,CAAC;AAKlC,eAAO,MAAM,sBAAsB,EAAE,WAAW,CAAC,qBAAqB,CAgGrE,CAAC"}
|
package/dist/tool-factory.js
CHANGED
|
@@ -5,6 +5,7 @@ import { createReadMediaFileTool } from "./read-media-file-tool.js";
|
|
|
5
5
|
import { createWriteFileTool } from "./write-file-tool.js";
|
|
6
6
|
import { createEditFileTool } from "./edit-file-tool.js";
|
|
7
7
|
import { createGlobFilesTool } from "./glob-files-tool.js";
|
|
8
|
+
import { createBlockedPathCheck } from "./blocked-path-check.js";
|
|
8
9
|
import { createGrepContentTool } from "./grep-content-tool.js";
|
|
9
10
|
import { isPathApprovedByDirectoryKey } from "./directory-approval.js";
|
|
10
11
|
import {
|
|
@@ -72,13 +73,16 @@ const fileSystemToolsFactory = {
|
|
|
72
73
|
await scopedFileSystemService.initialize();
|
|
73
74
|
return scopedFileSystemService;
|
|
74
75
|
};
|
|
76
|
+
const blockedPathCheck = createBlockedPathCheck({
|
|
77
|
+
...fileSystemConfig
|
|
78
|
+
});
|
|
75
79
|
const toolCreators = {
|
|
76
|
-
read_file: () => createReadFileTool(getFileSystemService),
|
|
80
|
+
read_file: () => createReadFileTool(getFileSystemService, blockedPathCheck, config.maxFileSize),
|
|
77
81
|
read_media_file: () => createReadMediaFileTool(getFileSystemService),
|
|
78
|
-
write_file: () => createWriteFileTool(getFileSystemService),
|
|
79
|
-
edit_file: () => createEditFileTool(getFileSystemService),
|
|
80
|
-
glob_files: () => createGlobFilesTool(getFileSystemService),
|
|
81
|
-
grep_content: () => createGrepContentTool(getFileSystemService)
|
|
82
|
+
write_file: () => createWriteFileTool(getFileSystemService, blockedPathCheck),
|
|
83
|
+
edit_file: () => createEditFileTool(getFileSystemService, blockedPathCheck, config.maxFileSize),
|
|
84
|
+
glob_files: () => createGlobFilesTool(getFileSystemService, blockedPathCheck),
|
|
85
|
+
grep_content: () => createGrepContentTool(getFileSystemService, blockedPathCheck)
|
|
82
86
|
};
|
|
83
87
|
const toolsToCreate = config.enabledTools ?? FILESYSTEM_TOOL_NAMES;
|
|
84
88
|
return toolsToCreate.map((toolName) => toolCreators[toolName]());
|
package/dist/workspace-paths.cjs
CHANGED
|
@@ -34,6 +34,7 @@ __export(workspace_paths_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(workspace_paths_exports);
|
|
36
36
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
37
|
+
var import_minimatch = require("minimatch");
|
|
37
38
|
var import_errors = require("@dexto/core/errors");
|
|
38
39
|
var import_workspace = require("@dexto/core/workspace");
|
|
39
40
|
var import_tools = require("@dexto/core/tools");
|
|
@@ -62,7 +63,10 @@ function isWorkspaceFileNotFound(error) {
|
|
|
62
63
|
return typeof error === "object" && error !== null && "code" in error && error.code === import_workspace.WorkspaceErrorCodes.FILE_NOT_FOUND;
|
|
63
64
|
}
|
|
64
65
|
function assertWorkspaceRelativeGlob(toolName, pattern) {
|
|
65
|
-
|
|
66
|
+
const escapes = (0, import_minimatch.braceExpand)(pattern).some(
|
|
67
|
+
(expanded) => import_node_path.default.isAbsolute(expanded) || expanded.split(/[\\/]/).includes("..")
|
|
68
|
+
);
|
|
69
|
+
if (escapes) {
|
|
66
70
|
throw import_tools.ToolError.validationFailed(
|
|
67
71
|
toolName,
|
|
68
72
|
`Glob pattern must stay inside the active workspace: ${pattern}`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace-paths.d.ts","sourceRoot":"","sources":["../src/workspace-paths.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workspace-paths.d.ts","sourceRoot":"","sources":["../src/workspace-paths.ts"],"names":[],"mappings":"AAMA,wBAAgB,uBAAuB,CACnC,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,GACjB,MAAM,CAkBR;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAU/D;AAED,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAYnF"}
|
package/dist/workspace-paths.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { braceExpand } from "minimatch";
|
|
2
3
|
import { DextoRuntimeError } from "@dexto/core/errors";
|
|
3
4
|
import { WorkspaceErrorCodes } from "@dexto/core/workspace";
|
|
4
5
|
import { ToolError } from "@dexto/core/tools";
|
|
@@ -27,7 +28,10 @@ function isWorkspaceFileNotFound(error) {
|
|
|
27
28
|
return typeof error === "object" && error !== null && "code" in error && error.code === WorkspaceErrorCodes.FILE_NOT_FOUND;
|
|
28
29
|
}
|
|
29
30
|
function assertWorkspaceRelativeGlob(toolName, pattern) {
|
|
30
|
-
|
|
31
|
+
const escapes = braceExpand(pattern).some(
|
|
32
|
+
(expanded) => path.isAbsolute(expanded) || expanded.split(/[\\/]/).includes("..")
|
|
33
|
+
);
|
|
34
|
+
if (escapes) {
|
|
31
35
|
throw ToolError.validationFailed(
|
|
32
36
|
toolName,
|
|
33
37
|
`Glob pattern must stay inside the active workspace: ${pattern}`,
|
package/dist/write-file-tool.cjs
CHANGED
|
@@ -28,6 +28,7 @@ var import_tools = require("@dexto/core/tools");
|
|
|
28
28
|
var import_errors = require("@dexto/core/errors");
|
|
29
29
|
var import_error_codes = require("./error-codes.js");
|
|
30
30
|
var import_directory_approval = require("./directory-approval.js");
|
|
31
|
+
var import_blocked_path_check = require("./blocked-path-check.js");
|
|
31
32
|
var import_workspace_paths = require("./workspace-paths.js");
|
|
32
33
|
const previewContentHashCache = /* @__PURE__ */ new Map();
|
|
33
34
|
const FILE_NOT_EXISTS_MARKER = null;
|
|
@@ -56,7 +57,7 @@ function generateDiffPreview(filePath, originalContent, newContent) {
|
|
|
56
57
|
deletions
|
|
57
58
|
};
|
|
58
59
|
}
|
|
59
|
-
function createWriteFileTool(getFileSystemService) {
|
|
60
|
+
function createWriteFileTool(getFileSystemService, blockedPathCheck) {
|
|
60
61
|
return (0, import_tools.defineTool)({
|
|
61
62
|
id: "write_file",
|
|
62
63
|
aliases: ["write"],
|
|
@@ -182,6 +183,12 @@ function createWriteFileTool(getFileSystemService) {
|
|
|
182
183
|
handle.context.path,
|
|
183
184
|
file_path
|
|
184
185
|
);
|
|
186
|
+
await (0, import_blocked_path_check.assertPathNotBlocked)(
|
|
187
|
+
blockedPathCheck,
|
|
188
|
+
handle.context.path,
|
|
189
|
+
workspacePath,
|
|
190
|
+
context.logger
|
|
191
|
+
);
|
|
185
192
|
let originalContent = null;
|
|
186
193
|
let fileExistsNow = false;
|
|
187
194
|
try {
|
|
@@ -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 WriteFileInputSchema: z.ZodObject<{
|
|
10
11
|
file_path: z.ZodString;
|
|
11
12
|
content: z.ZodString;
|
|
@@ -19,6 +20,6 @@ declare const WriteFileInputSchema: z.ZodObject<{
|
|
|
19
20
|
/**
|
|
20
21
|
* Create the write_file internal tool with directory approval support
|
|
21
22
|
*/
|
|
22
|
-
export declare function createWriteFileTool(getFileSystemService: FileSystemServiceGetter): Tool<typeof WriteFileInputSchema>;
|
|
23
|
+
export declare function createWriteFileTool(getFileSystemService: FileSystemServiceGetter, blockedPathCheck: BlockedPathCheck): Tool<typeof WriteFileInputSchema>;
|
|
23
24
|
export {};
|
|
24
25
|
//# sourceMappingURL=write-file-tool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-file-tool.d.ts","sourceRoot":"","sources":["../src/write-file-tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB,OAAO,KAAK,EAGR,IAAI,EAEP,MAAM,mBAAmB,CAAC;AAG3B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"write-file-tool.d.ts","sourceRoot":"","sources":["../src/write-file-tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB,OAAO,KAAK,EAGR,IAAI,EAEP,MAAM,mBAAmB,CAAC;AAG3B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAEpE,OAAO,EAAwB,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAuBtF,QAAA,MAAM,oBAAoB;;;;;;;;;kBAeb,CAAC;AA0Bd;;GAEG;AACH,wBAAgB,mBAAmB,CAC/B,oBAAoB,EAAE,uBAAuB,EAC7C,gBAAgB,EAAE,gBAAgB,GACnC,IAAI,CAAC,OAAO,oBAAoB,CAAC,CA0OnC"}
|
package/dist/write-file-tool.js
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { DextoRuntimeError } from "@dexto/core/errors";
|
|
12
12
|
import { FileSystemErrorCode } from "./error-codes.js";
|
|
13
13
|
import { createDirectoryAccessApprovalHandlers, resolveFilePath } from "./directory-approval.js";
|
|
14
|
+
import { assertPathNotBlocked } from "./blocked-path-check.js";
|
|
14
15
|
import { isWorkspaceFileNotFound, toWorkspaceRelativePath } from "./workspace-paths.js";
|
|
15
16
|
const previewContentHashCache = /* @__PURE__ */ new Map();
|
|
16
17
|
const FILE_NOT_EXISTS_MARKER = null;
|
|
@@ -39,7 +40,7 @@ function generateDiffPreview(filePath, originalContent, newContent) {
|
|
|
39
40
|
deletions
|
|
40
41
|
};
|
|
41
42
|
}
|
|
42
|
-
function createWriteFileTool(getFileSystemService) {
|
|
43
|
+
function createWriteFileTool(getFileSystemService, blockedPathCheck) {
|
|
43
44
|
return defineTool({
|
|
44
45
|
id: "write_file",
|
|
45
46
|
aliases: ["write"],
|
|
@@ -165,6 +166,12 @@ function createWriteFileTool(getFileSystemService) {
|
|
|
165
166
|
handle.context.path,
|
|
166
167
|
file_path
|
|
167
168
|
);
|
|
169
|
+
await assertPathNotBlocked(
|
|
170
|
+
blockedPathCheck,
|
|
171
|
+
handle.context.path,
|
|
172
|
+
workspacePath,
|
|
173
|
+
context.logger
|
|
174
|
+
);
|
|
168
175
|
let originalContent = null;
|
|
169
176
|
let fileExistsNow = false;
|
|
170
177
|
try {
|