@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
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var blocked_path_check_exports = {};
|
|
30
|
+
__export(blocked_path_check_exports, {
|
|
31
|
+
assertPathNotBlocked: () => assertPathNotBlocked,
|
|
32
|
+
createBlockedPathCheck: () => createBlockedPathCheck
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(blocked_path_check_exports);
|
|
35
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
36
|
+
var import_errors = require("./errors.js");
|
|
37
|
+
var import_path_validator = require("./path-validator.js");
|
|
38
|
+
function createBlockedPathCheck(config) {
|
|
39
|
+
const validators = /* @__PURE__ */ new Map();
|
|
40
|
+
return async (workspaceRoot, workspacePath, logger) => {
|
|
41
|
+
let validator = validators.get(workspaceRoot);
|
|
42
|
+
if (validator === void 0) {
|
|
43
|
+
validator = new import_path_validator.PathValidator({ ...config, workingDirectory: workspaceRoot }, logger);
|
|
44
|
+
validators.set(workspaceRoot, validator);
|
|
45
|
+
}
|
|
46
|
+
const validation = await validator.validatePathForPreview(
|
|
47
|
+
import_node_path.default.resolve(workspaceRoot, workspacePath)
|
|
48
|
+
);
|
|
49
|
+
return validation.isValid ? null : validation.error ?? "Path is not allowed";
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
async function assertPathNotBlocked(check, workspaceRoot, workspacePath, logger) {
|
|
53
|
+
const reason = await check(workspaceRoot, workspacePath, logger);
|
|
54
|
+
if (reason !== null) {
|
|
55
|
+
throw import_errors.FileSystemError.invalidPath(workspacePath, reason);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
+
0 && (module.exports = {
|
|
60
|
+
assertPathNotBlocked,
|
|
61
|
+
createBlockedPathCheck
|
|
62
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Logger } from '@dexto/core/logger';
|
|
2
|
+
import type { FileSystemConfig } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Returns the reason a workspace path is blocked by the configured blocked paths and blocked
|
|
5
|
+
* extensions, or null when it is not blocked. Relative blocked paths resolve against the
|
|
6
|
+
* workspace root.
|
|
7
|
+
*/
|
|
8
|
+
export type BlockedPathCheck = (workspaceRoot: string, workspacePath: string, logger: Logger) => Promise<string | null>;
|
|
9
|
+
export declare function createBlockedPathCheck(config: FileSystemConfig): BlockedPathCheck;
|
|
10
|
+
export declare function assertPathNotBlocked(check: BlockedPathCheck, workspaceRoot: string, workspacePath: string, logger: Logger): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=blocked-path-check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocked-path-check.d.ts","sourceRoot":"","sources":["../src/blocked-path-check.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAGjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAC3B,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,KACb,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;AAE5B,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,gBAAgB,GAAG,gBAAgB,CAajF;AAED,wBAAsB,oBAAoB,CACtC,KAAK,EAAE,gBAAgB,EACvB,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAKf"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { FileSystemError } from "./errors.js";
|
|
3
|
+
import { PathValidator } from "./path-validator.js";
|
|
4
|
+
function createBlockedPathCheck(config) {
|
|
5
|
+
const validators = /* @__PURE__ */ new Map();
|
|
6
|
+
return async (workspaceRoot, workspacePath, logger) => {
|
|
7
|
+
let validator = validators.get(workspaceRoot);
|
|
8
|
+
if (validator === void 0) {
|
|
9
|
+
validator = new PathValidator({ ...config, workingDirectory: workspaceRoot }, logger);
|
|
10
|
+
validators.set(workspaceRoot, validator);
|
|
11
|
+
}
|
|
12
|
+
const validation = await validator.validatePathForPreview(
|
|
13
|
+
path.resolve(workspaceRoot, workspacePath)
|
|
14
|
+
);
|
|
15
|
+
return validation.isValid ? null : validation.error ?? "Path is not allowed";
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
async function assertPathNotBlocked(check, workspaceRoot, workspacePath, logger) {
|
|
19
|
+
const reason = await check(workspaceRoot, workspacePath, logger);
|
|
20
|
+
if (reason !== null) {
|
|
21
|
+
throw FileSystemError.invalidPath(workspacePath, reason);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
assertPathNotBlocked,
|
|
26
|
+
createBlockedPathCheck
|
|
27
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_core = require("@dexto/core");
|
|
3
|
+
var import_storage = require("@dexto/core/storage");
|
|
4
|
+
var import_vitest = require("vitest");
|
|
5
|
+
var import_blocked_path_check = require("./blocked-path-check.js");
|
|
6
|
+
var import_edit_file_tool = require("./edit-file-tool.js");
|
|
7
|
+
var import_grep_content_tool = require("./grep-content-tool.js");
|
|
8
|
+
var import_read_file_tool = require("./read-file-tool.js");
|
|
9
|
+
var import_write_file_tool = require("./write-file-tool.js");
|
|
10
|
+
const blockedPathCheck = (0, import_blocked_path_check.createBlockedPathCheck)({
|
|
11
|
+
allowedPaths: ["."],
|
|
12
|
+
blockedPaths: [".git", ".env"],
|
|
13
|
+
blockedExtensions: [".so"],
|
|
14
|
+
maxFileSize: 1024,
|
|
15
|
+
enableBackups: false,
|
|
16
|
+
backupRetentionDays: 7
|
|
17
|
+
});
|
|
18
|
+
async function createContext(files) {
|
|
19
|
+
const stores = new import_storage.InMemoryDextoStores();
|
|
20
|
+
await stores.connect();
|
|
21
|
+
const logger = (0, import_core.createLogger)({
|
|
22
|
+
agentId: "test-agent",
|
|
23
|
+
config: { level: "error", transports: [{ type: "silent" }] }
|
|
24
|
+
});
|
|
25
|
+
const workspaceManager = new import_core.WorkspaceManager(
|
|
26
|
+
stores.getStore("workspaces"),
|
|
27
|
+
new import_core.AgentEventBus(),
|
|
28
|
+
logger,
|
|
29
|
+
{
|
|
30
|
+
open: import_vitest.vi.fn(async ({ context }) => ({
|
|
31
|
+
context,
|
|
32
|
+
capabilities: ["files"],
|
|
33
|
+
files: {
|
|
34
|
+
readFile: async (file) => files.get(file) ?? "",
|
|
35
|
+
readText: async (file) => files.get(file) ?? "",
|
|
36
|
+
glob: async () => [...files.keys()],
|
|
37
|
+
writeFile: async (file, content) => {
|
|
38
|
+
files.set(file, content);
|
|
39
|
+
},
|
|
40
|
+
listFiles: async () => [...files.keys()]
|
|
41
|
+
}
|
|
42
|
+
}))
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
await workspaceManager.setWorkspace({ path: "/repo" });
|
|
46
|
+
return {
|
|
47
|
+
logger,
|
|
48
|
+
services: {
|
|
49
|
+
approval: {},
|
|
50
|
+
search: {},
|
|
51
|
+
resources: {},
|
|
52
|
+
prompts: {},
|
|
53
|
+
skills: {},
|
|
54
|
+
mcp: {},
|
|
55
|
+
taskForker: null,
|
|
56
|
+
workspaceManager
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
(0, import_vitest.describe)("blocked paths in file tools", () => {
|
|
61
|
+
(0, import_vitest.it)("reports a blocked path and an allowed one", async () => {
|
|
62
|
+
const logger = (await createContext(/* @__PURE__ */ new Map())).logger;
|
|
63
|
+
(0, import_vitest.expect)(await blockedPathCheck("/repo", ".env", logger)).not.toBeNull();
|
|
64
|
+
(0, import_vitest.expect)(await blockedPathCheck("/repo", ".git/hooks/pre-commit", logger)).not.toBeNull();
|
|
65
|
+
(0, import_vitest.expect)(await blockedPathCheck("/repo", "lib/native.so", logger)).not.toBeNull();
|
|
66
|
+
(0, import_vitest.expect)(await blockedPathCheck("/repo", "src/index.ts", logger)).toBeNull();
|
|
67
|
+
});
|
|
68
|
+
(0, import_vitest.it)("read_file refuses a blocked file", async () => {
|
|
69
|
+
const context = await createContext(/* @__PURE__ */ new Map([[".env", "SECRET=1"]]));
|
|
70
|
+
const tool = (0, import_read_file_tool.createReadFileTool)(import_vitest.vi.fn(), blockedPathCheck, 1024);
|
|
71
|
+
await (0, import_vitest.expect)(tool.execute({ file_path: ".env" }, context)).rejects.toThrow(/blocked/);
|
|
72
|
+
});
|
|
73
|
+
(0, import_vitest.it)("write_file and edit_file refuse a blocked file", async () => {
|
|
74
|
+
const files = /* @__PURE__ */ new Map([[".git/config", "x"]]);
|
|
75
|
+
const context = await createContext(files);
|
|
76
|
+
const write = (0, import_write_file_tool.createWriteFileTool)(import_vitest.vi.fn(), blockedPathCheck);
|
|
77
|
+
const edit = (0, import_edit_file_tool.createEditFileTool)(import_vitest.vi.fn(), blockedPathCheck, 1024);
|
|
78
|
+
await (0, import_vitest.expect)(
|
|
79
|
+
write.execute({ file_path: ".git/config", content: "y", encoding: "utf-8" }, context)
|
|
80
|
+
).rejects.toThrow(/blocked/);
|
|
81
|
+
await (0, import_vitest.expect)(
|
|
82
|
+
edit.execute(
|
|
83
|
+
{
|
|
84
|
+
file_path: ".git/config",
|
|
85
|
+
old_string: "x",
|
|
86
|
+
new_string: "y",
|
|
87
|
+
replace_all: false
|
|
88
|
+
},
|
|
89
|
+
context
|
|
90
|
+
)
|
|
91
|
+
).rejects.toThrow(/blocked/);
|
|
92
|
+
(0, import_vitest.expect)(files.get(".git/config")).toBe("x");
|
|
93
|
+
});
|
|
94
|
+
(0, import_vitest.it)("grep_content skips blocked files", async () => {
|
|
95
|
+
const context = await createContext(
|
|
96
|
+
/* @__PURE__ */ new Map([
|
|
97
|
+
[".env", "API_KEY=hidden"],
|
|
98
|
+
["src/a.ts", "API_KEY=visible"]
|
|
99
|
+
])
|
|
100
|
+
);
|
|
101
|
+
const tool = (0, import_grep_content_tool.createGrepContentTool)(import_vitest.vi.fn(), blockedPathCheck);
|
|
102
|
+
const result = JSON.stringify(
|
|
103
|
+
await tool.execute(
|
|
104
|
+
{
|
|
105
|
+
pattern: "API_KEY",
|
|
106
|
+
glob: "**/*",
|
|
107
|
+
context_lines: 0,
|
|
108
|
+
case_insensitive: false,
|
|
109
|
+
max_results: 10
|
|
110
|
+
},
|
|
111
|
+
context
|
|
112
|
+
)
|
|
113
|
+
);
|
|
114
|
+
(0, import_vitest.expect)(result).toContain("visible");
|
|
115
|
+
(0, import_vitest.expect)(result).not.toContain("hidden");
|
|
116
|
+
});
|
|
117
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocked-path-check.test.d.ts","sourceRoot":"","sources":["../src/blocked-path-check.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { AgentEventBus, createLogger, WorkspaceManager } from "@dexto/core";
|
|
2
|
+
import { InMemoryDextoStores } from "@dexto/core/storage";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { createBlockedPathCheck } from "./blocked-path-check.js";
|
|
5
|
+
import { createEditFileTool } from "./edit-file-tool.js";
|
|
6
|
+
import { createGrepContentTool } from "./grep-content-tool.js";
|
|
7
|
+
import { createReadFileTool } from "./read-file-tool.js";
|
|
8
|
+
import { createWriteFileTool } from "./write-file-tool.js";
|
|
9
|
+
const blockedPathCheck = createBlockedPathCheck({
|
|
10
|
+
allowedPaths: ["."],
|
|
11
|
+
blockedPaths: [".git", ".env"],
|
|
12
|
+
blockedExtensions: [".so"],
|
|
13
|
+
maxFileSize: 1024,
|
|
14
|
+
enableBackups: false,
|
|
15
|
+
backupRetentionDays: 7
|
|
16
|
+
});
|
|
17
|
+
async function createContext(files) {
|
|
18
|
+
const stores = new InMemoryDextoStores();
|
|
19
|
+
await stores.connect();
|
|
20
|
+
const logger = createLogger({
|
|
21
|
+
agentId: "test-agent",
|
|
22
|
+
config: { level: "error", transports: [{ type: "silent" }] }
|
|
23
|
+
});
|
|
24
|
+
const workspaceManager = new WorkspaceManager(
|
|
25
|
+
stores.getStore("workspaces"),
|
|
26
|
+
new AgentEventBus(),
|
|
27
|
+
logger,
|
|
28
|
+
{
|
|
29
|
+
open: vi.fn(async ({ context }) => ({
|
|
30
|
+
context,
|
|
31
|
+
capabilities: ["files"],
|
|
32
|
+
files: {
|
|
33
|
+
readFile: async (file) => files.get(file) ?? "",
|
|
34
|
+
readText: async (file) => files.get(file) ?? "",
|
|
35
|
+
glob: async () => [...files.keys()],
|
|
36
|
+
writeFile: async (file, content) => {
|
|
37
|
+
files.set(file, content);
|
|
38
|
+
},
|
|
39
|
+
listFiles: async () => [...files.keys()]
|
|
40
|
+
}
|
|
41
|
+
}))
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
await workspaceManager.setWorkspace({ path: "/repo" });
|
|
45
|
+
return {
|
|
46
|
+
logger,
|
|
47
|
+
services: {
|
|
48
|
+
approval: {},
|
|
49
|
+
search: {},
|
|
50
|
+
resources: {},
|
|
51
|
+
prompts: {},
|
|
52
|
+
skills: {},
|
|
53
|
+
mcp: {},
|
|
54
|
+
taskForker: null,
|
|
55
|
+
workspaceManager
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
describe("blocked paths in file tools", () => {
|
|
60
|
+
it("reports a blocked path and an allowed one", async () => {
|
|
61
|
+
const logger = (await createContext(/* @__PURE__ */ new Map())).logger;
|
|
62
|
+
expect(await blockedPathCheck("/repo", ".env", logger)).not.toBeNull();
|
|
63
|
+
expect(await blockedPathCheck("/repo", ".git/hooks/pre-commit", logger)).not.toBeNull();
|
|
64
|
+
expect(await blockedPathCheck("/repo", "lib/native.so", logger)).not.toBeNull();
|
|
65
|
+
expect(await blockedPathCheck("/repo", "src/index.ts", logger)).toBeNull();
|
|
66
|
+
});
|
|
67
|
+
it("read_file refuses a blocked file", async () => {
|
|
68
|
+
const context = await createContext(/* @__PURE__ */ new Map([[".env", "SECRET=1"]]));
|
|
69
|
+
const tool = createReadFileTool(vi.fn(), blockedPathCheck, 1024);
|
|
70
|
+
await expect(tool.execute({ file_path: ".env" }, context)).rejects.toThrow(/blocked/);
|
|
71
|
+
});
|
|
72
|
+
it("write_file and edit_file refuse a blocked file", async () => {
|
|
73
|
+
const files = /* @__PURE__ */ new Map([[".git/config", "x"]]);
|
|
74
|
+
const context = await createContext(files);
|
|
75
|
+
const write = createWriteFileTool(vi.fn(), blockedPathCheck);
|
|
76
|
+
const edit = createEditFileTool(vi.fn(), blockedPathCheck, 1024);
|
|
77
|
+
await expect(
|
|
78
|
+
write.execute({ file_path: ".git/config", content: "y", encoding: "utf-8" }, context)
|
|
79
|
+
).rejects.toThrow(/blocked/);
|
|
80
|
+
await expect(
|
|
81
|
+
edit.execute(
|
|
82
|
+
{
|
|
83
|
+
file_path: ".git/config",
|
|
84
|
+
old_string: "x",
|
|
85
|
+
new_string: "y",
|
|
86
|
+
replace_all: false
|
|
87
|
+
},
|
|
88
|
+
context
|
|
89
|
+
)
|
|
90
|
+
).rejects.toThrow(/blocked/);
|
|
91
|
+
expect(files.get(".git/config")).toBe("x");
|
|
92
|
+
});
|
|
93
|
+
it("grep_content skips blocked files", async () => {
|
|
94
|
+
const context = await createContext(
|
|
95
|
+
/* @__PURE__ */ new Map([
|
|
96
|
+
[".env", "API_KEY=hidden"],
|
|
97
|
+
["src/a.ts", "API_KEY=visible"]
|
|
98
|
+
])
|
|
99
|
+
);
|
|
100
|
+
const tool = createGrepContentTool(vi.fn(), blockedPathCheck);
|
|
101
|
+
const result = JSON.stringify(
|
|
102
|
+
await tool.execute(
|
|
103
|
+
{
|
|
104
|
+
pattern: "API_KEY",
|
|
105
|
+
glob: "**/*",
|
|
106
|
+
context_lines: 0,
|
|
107
|
+
case_insensitive: false,
|
|
108
|
+
max_results: 10
|
|
109
|
+
},
|
|
110
|
+
context
|
|
111
|
+
)
|
|
112
|
+
);
|
|
113
|
+
expect(result).toContain("visible");
|
|
114
|
+
expect(result).not.toContain("hidden");
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -22,6 +22,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
mod
|
|
23
23
|
));
|
|
24
24
|
var import_vitest = require("vitest");
|
|
25
|
+
var import_test_helpers = require("./test-helpers.js");
|
|
25
26
|
var path = __toESM(require("node:path"), 1);
|
|
26
27
|
var fs = __toESM(require("node:fs/promises"), 1);
|
|
27
28
|
var os = __toESM(require("node:os"), 1);
|
|
@@ -163,7 +164,7 @@ async function readWorkspaceFile(resolvedPath, filePath) {
|
|
|
163
164
|
});
|
|
164
165
|
(0, import_vitest.describe)("needsApproval", () => {
|
|
165
166
|
(0, import_vitest.it)("should return false for paths within config-allowed roots", async () => {
|
|
166
|
-
const tool = (0, import_read_file_tool.createReadFileTool)(getFileSystemService);
|
|
167
|
+
const tool = (0, import_read_file_tool.createReadFileTool)(getFileSystemService, import_test_helpers.allowAllPaths, 10 * 1024 * 1024);
|
|
167
168
|
const needsApproval = tool.needsApproval;
|
|
168
169
|
(0, import_vitest.expect)(needsApproval).toBeDefined();
|
|
169
170
|
const testFile = path.join(tempDir, "test.txt");
|
|
@@ -176,7 +177,7 @@ async function readWorkspaceFile(resolvedPath, filePath) {
|
|
|
176
177
|
(0, import_vitest.expect)(decision).toBe(false);
|
|
177
178
|
});
|
|
178
179
|
(0, import_vitest.it)("should return a directory approval key for external paths", async () => {
|
|
179
|
-
const tool = (0, import_read_file_tool.createReadFileTool)(getFileSystemService);
|
|
180
|
+
const tool = (0, import_read_file_tool.createReadFileTool)(getFileSystemService, import_test_helpers.allowAllPaths, 10 * 1024 * 1024);
|
|
180
181
|
const needsApproval = tool.needsApproval;
|
|
181
182
|
(0, import_vitest.expect)(needsApproval).toBeDefined();
|
|
182
183
|
const externalPath = "/external/project/file.ts";
|
|
@@ -194,7 +195,7 @@ async function readWorkspaceFile(resolvedPath, filePath) {
|
|
|
194
195
|
(0, import_directory_approval.createDirectoryApprovalKey)("/external/project"),
|
|
195
196
|
"session"
|
|
196
197
|
);
|
|
197
|
-
const tool = (0, import_read_file_tool.createReadFileTool)(getFileSystemService);
|
|
198
|
+
const tool = (0, import_read_file_tool.createReadFileTool)(getFileSystemService, import_test_helpers.allowAllPaths, 10 * 1024 * 1024);
|
|
198
199
|
const needsApproval = tool.needsApproval;
|
|
199
200
|
(0, import_vitest.expect)(needsApproval).toBeDefined();
|
|
200
201
|
const externalPath = "/external/project/file.ts";
|
|
@@ -210,7 +211,7 @@ async function readWorkspaceFile(resolvedPath, filePath) {
|
|
|
210
211
|
(0, import_directory_approval.createDirectoryApprovalKey)("/external/project"),
|
|
211
212
|
"once"
|
|
212
213
|
);
|
|
213
|
-
const tool = (0, import_read_file_tool.createReadFileTool)(getFileSystemService);
|
|
214
|
+
const tool = (0, import_read_file_tool.createReadFileTool)(getFileSystemService, import_test_helpers.allowAllPaths, 10 * 1024 * 1024);
|
|
214
215
|
const needsApproval = tool.needsApproval;
|
|
215
216
|
(0, import_vitest.expect)(needsApproval).toBeDefined();
|
|
216
217
|
const externalPath = "/external/project/file.ts";
|
|
@@ -222,7 +223,7 @@ async function readWorkspaceFile(resolvedPath, filePath) {
|
|
|
222
223
|
(0, import_vitest.expect)(decision).toBe((0, import_directory_approval.createDirectoryApprovalKey)("/external/project", "read"));
|
|
223
224
|
});
|
|
224
225
|
(0, import_vitest.it)("should remember directory approvals only for the granting session", async () => {
|
|
225
|
-
const tool = (0, import_read_file_tool.createReadFileTool)(getFileSystemService);
|
|
226
|
+
const tool = (0, import_read_file_tool.createReadFileTool)(getFileSystemService, import_test_helpers.allowAllPaths, 10 * 1024 * 1024);
|
|
226
227
|
const needsApproval = tool.needsApproval;
|
|
227
228
|
(0, import_vitest.expect)(needsApproval).toBeDefined();
|
|
228
229
|
const externalPath = "/external/project/file.ts";
|
|
@@ -253,7 +254,7 @@ async function readWorkspaceFile(resolvedPath, filePath) {
|
|
|
253
254
|
});
|
|
254
255
|
(0, import_vitest.describe)("Different tool operations", () => {
|
|
255
256
|
(0, import_vitest.it)("should return a directory key for write operations", async () => {
|
|
256
|
-
const tool = (0, import_write_file_tool.createWriteFileTool)(getFileSystemService);
|
|
257
|
+
const tool = (0, import_write_file_tool.createWriteFileTool)(getFileSystemService, import_test_helpers.allowAllPaths);
|
|
257
258
|
const needsApproval = tool.needsApproval;
|
|
258
259
|
(0, import_vitest.expect)(needsApproval).toBeDefined();
|
|
259
260
|
const externalPath = "/external/project/new.ts";
|
|
@@ -267,7 +268,7 @@ async function readWorkspaceFile(resolvedPath, filePath) {
|
|
|
267
268
|
);
|
|
268
269
|
});
|
|
269
270
|
(0, import_vitest.it)("should return a directory key for edit operations", async () => {
|
|
270
|
-
const tool = (0, import_edit_file_tool.createEditFileTool)(getFileSystemService);
|
|
271
|
+
const tool = (0, import_edit_file_tool.createEditFileTool)(getFileSystemService, import_test_helpers.allowAllPaths, 10 * 1024 * 1024);
|
|
271
272
|
const needsApproval = tool.needsApproval;
|
|
272
273
|
(0, import_vitest.expect)(needsApproval).toBeDefined();
|
|
273
274
|
const externalPath = "/external/project/existing.ts";
|
|
@@ -287,7 +288,7 @@ async function readWorkspaceFile(resolvedPath, filePath) {
|
|
|
287
288
|
});
|
|
288
289
|
(0, import_vitest.describe)("Path containment scenarios", () => {
|
|
289
290
|
(0, import_vitest.it)("should cover child paths when parent directory is session-approved", async () => {
|
|
290
|
-
const tool = (0, import_read_file_tool.createReadFileTool)(getFileSystemService);
|
|
291
|
+
const tool = (0, import_read_file_tool.createReadFileTool)(getFileSystemService, import_test_helpers.allowAllPaths, 10 * 1024 * 1024);
|
|
291
292
|
const needsApproval = tool.needsApproval;
|
|
292
293
|
(0, import_vitest.expect)(needsApproval).toBeDefined();
|
|
293
294
|
await approvalManager.addApprovedKey(
|
|
@@ -308,7 +309,7 @@ async function readWorkspaceFile(resolvedPath, filePath) {
|
|
|
308
309
|
(0, import_vitest.expect)(decision2).toBe(false);
|
|
309
310
|
});
|
|
310
311
|
(0, import_vitest.it)("should NOT cover sibling directories", async () => {
|
|
311
|
-
const tool = (0, import_read_file_tool.createReadFileTool)(getFileSystemService);
|
|
312
|
+
const tool = (0, import_read_file_tool.createReadFileTool)(getFileSystemService, import_test_helpers.allowAllPaths, 10 * 1024 * 1024);
|
|
312
313
|
const needsApproval = tool.needsApproval;
|
|
313
314
|
(0, import_vitest.expect)(needsApproval).toBeDefined();
|
|
314
315
|
await approvalManager.addApprovedKey(
|
|
@@ -333,7 +334,7 @@ async function readWorkspaceFile(resolvedPath, filePath) {
|
|
|
333
334
|
(0, import_directory_approval.createDirectoryApprovalKey)("/external/project", "read"),
|
|
334
335
|
"session"
|
|
335
336
|
);
|
|
336
|
-
const writeTool = (0, import_write_file_tool.createWriteFileTool)(getFileSystemService);
|
|
337
|
+
const writeTool = (0, import_write_file_tool.createWriteFileTool)(getFileSystemService, import_test_helpers.allowAllPaths);
|
|
337
338
|
const needsApproval = writeTool.needsApproval;
|
|
338
339
|
(0, import_vitest.expect)(needsApproval).toBeDefined();
|
|
339
340
|
await (0, import_vitest.expect)(
|
|
@@ -531,7 +532,7 @@ async function readWorkspaceFile(resolvedPath, filePath) {
|
|
|
531
532
|
});
|
|
532
533
|
(0, import_vitest.describe)("Without ApprovalManager in context", () => {
|
|
533
534
|
(0, import_vitest.it)("should throw for external paths", async () => {
|
|
534
|
-
const tool = (0, import_read_file_tool.createReadFileTool)(getFileSystemService);
|
|
535
|
+
const tool = (0, import_read_file_tool.createReadFileTool)(getFileSystemService, import_test_helpers.allowAllPaths, 10 * 1024 * 1024);
|
|
535
536
|
const needsApproval = tool.needsApproval;
|
|
536
537
|
(0, import_vitest.expect)(needsApproval).toBeDefined();
|
|
537
538
|
const contextWithoutApprovalManager = { logger: mockLogger };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
|
2
|
+
import { allowAllPaths } from "./test-helpers.js";
|
|
2
3
|
import * as path from "node:path";
|
|
3
4
|
import * as fs from "node:fs/promises";
|
|
4
5
|
import * as os from "node:os";
|
|
@@ -143,7 +144,7 @@ describe("Directory Approval Integration Tests", () => {
|
|
|
143
144
|
});
|
|
144
145
|
describe("needsApproval", () => {
|
|
145
146
|
it("should return false for paths within config-allowed roots", async () => {
|
|
146
|
-
const tool = createReadFileTool(getFileSystemService);
|
|
147
|
+
const tool = createReadFileTool(getFileSystemService, allowAllPaths, 10 * 1024 * 1024);
|
|
147
148
|
const needsApproval = tool.needsApproval;
|
|
148
149
|
expect(needsApproval).toBeDefined();
|
|
149
150
|
const testFile = path.join(tempDir, "test.txt");
|
|
@@ -156,7 +157,7 @@ describe("Directory Approval Integration Tests", () => {
|
|
|
156
157
|
expect(decision).toBe(false);
|
|
157
158
|
});
|
|
158
159
|
it("should return a directory approval key for external paths", async () => {
|
|
159
|
-
const tool = createReadFileTool(getFileSystemService);
|
|
160
|
+
const tool = createReadFileTool(getFileSystemService, allowAllPaths, 10 * 1024 * 1024);
|
|
160
161
|
const needsApproval = tool.needsApproval;
|
|
161
162
|
expect(needsApproval).toBeDefined();
|
|
162
163
|
const externalPath = "/external/project/file.ts";
|
|
@@ -174,7 +175,7 @@ describe("Directory Approval Integration Tests", () => {
|
|
|
174
175
|
createDirectoryApprovalKey("/external/project"),
|
|
175
176
|
"session"
|
|
176
177
|
);
|
|
177
|
-
const tool = createReadFileTool(getFileSystemService);
|
|
178
|
+
const tool = createReadFileTool(getFileSystemService, allowAllPaths, 10 * 1024 * 1024);
|
|
178
179
|
const needsApproval = tool.needsApproval;
|
|
179
180
|
expect(needsApproval).toBeDefined();
|
|
180
181
|
const externalPath = "/external/project/file.ts";
|
|
@@ -190,7 +191,7 @@ describe("Directory Approval Integration Tests", () => {
|
|
|
190
191
|
createDirectoryApprovalKey("/external/project"),
|
|
191
192
|
"once"
|
|
192
193
|
);
|
|
193
|
-
const tool = createReadFileTool(getFileSystemService);
|
|
194
|
+
const tool = createReadFileTool(getFileSystemService, allowAllPaths, 10 * 1024 * 1024);
|
|
194
195
|
const needsApproval = tool.needsApproval;
|
|
195
196
|
expect(needsApproval).toBeDefined();
|
|
196
197
|
const externalPath = "/external/project/file.ts";
|
|
@@ -202,7 +203,7 @@ describe("Directory Approval Integration Tests", () => {
|
|
|
202
203
|
expect(decision).toBe(createDirectoryApprovalKey("/external/project", "read"));
|
|
203
204
|
});
|
|
204
205
|
it("should remember directory approvals only for the granting session", async () => {
|
|
205
|
-
const tool = createReadFileTool(getFileSystemService);
|
|
206
|
+
const tool = createReadFileTool(getFileSystemService, allowAllPaths, 10 * 1024 * 1024);
|
|
206
207
|
const needsApproval = tool.needsApproval;
|
|
207
208
|
expect(needsApproval).toBeDefined();
|
|
208
209
|
const externalPath = "/external/project/file.ts";
|
|
@@ -233,7 +234,7 @@ describe("Directory Approval Integration Tests", () => {
|
|
|
233
234
|
});
|
|
234
235
|
describe("Different tool operations", () => {
|
|
235
236
|
it("should return a directory key for write operations", async () => {
|
|
236
|
-
const tool = createWriteFileTool(getFileSystemService);
|
|
237
|
+
const tool = createWriteFileTool(getFileSystemService, allowAllPaths);
|
|
237
238
|
const needsApproval = tool.needsApproval;
|
|
238
239
|
expect(needsApproval).toBeDefined();
|
|
239
240
|
const externalPath = "/external/project/new.ts";
|
|
@@ -247,7 +248,7 @@ describe("Directory Approval Integration Tests", () => {
|
|
|
247
248
|
);
|
|
248
249
|
});
|
|
249
250
|
it("should return a directory key for edit operations", async () => {
|
|
250
|
-
const tool = createEditFileTool(getFileSystemService);
|
|
251
|
+
const tool = createEditFileTool(getFileSystemService, allowAllPaths, 10 * 1024 * 1024);
|
|
251
252
|
const needsApproval = tool.needsApproval;
|
|
252
253
|
expect(needsApproval).toBeDefined();
|
|
253
254
|
const externalPath = "/external/project/existing.ts";
|
|
@@ -267,7 +268,7 @@ describe("Directory Approval Integration Tests", () => {
|
|
|
267
268
|
});
|
|
268
269
|
describe("Path containment scenarios", () => {
|
|
269
270
|
it("should cover child paths when parent directory is session-approved", async () => {
|
|
270
|
-
const tool = createReadFileTool(getFileSystemService);
|
|
271
|
+
const tool = createReadFileTool(getFileSystemService, allowAllPaths, 10 * 1024 * 1024);
|
|
271
272
|
const needsApproval = tool.needsApproval;
|
|
272
273
|
expect(needsApproval).toBeDefined();
|
|
273
274
|
await approvalManager.addApprovedKey(
|
|
@@ -288,7 +289,7 @@ describe("Directory Approval Integration Tests", () => {
|
|
|
288
289
|
expect(decision2).toBe(false);
|
|
289
290
|
});
|
|
290
291
|
it("should NOT cover sibling directories", async () => {
|
|
291
|
-
const tool = createReadFileTool(getFileSystemService);
|
|
292
|
+
const tool = createReadFileTool(getFileSystemService, allowAllPaths, 10 * 1024 * 1024);
|
|
292
293
|
const needsApproval = tool.needsApproval;
|
|
293
294
|
expect(needsApproval).toBeDefined();
|
|
294
295
|
await approvalManager.addApprovedKey(
|
|
@@ -313,7 +314,7 @@ describe("Directory Approval Integration Tests", () => {
|
|
|
313
314
|
createDirectoryApprovalKey("/external/project", "read"),
|
|
314
315
|
"session"
|
|
315
316
|
);
|
|
316
|
-
const writeTool = createWriteFileTool(getFileSystemService);
|
|
317
|
+
const writeTool = createWriteFileTool(getFileSystemService, allowAllPaths);
|
|
317
318
|
const needsApproval = writeTool.needsApproval;
|
|
318
319
|
expect(needsApproval).toBeDefined();
|
|
319
320
|
await expect(
|
|
@@ -511,7 +512,7 @@ describe("Directory Approval Integration Tests", () => {
|
|
|
511
512
|
});
|
|
512
513
|
describe("Without ApprovalManager in context", () => {
|
|
513
514
|
it("should throw for external paths", async () => {
|
|
514
|
-
const tool = createReadFileTool(getFileSystemService);
|
|
515
|
+
const tool = createReadFileTool(getFileSystemService, allowAllPaths, 10 * 1024 * 1024);
|
|
515
516
|
const needsApproval = tool.needsApproval;
|
|
516
517
|
expect(needsApproval).toBeDefined();
|
|
517
518
|
const contextWithoutApprovalManager = { logger: mockLogger };
|