@agentier/tools 0.1.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.
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Configuration options for the {@link readFileTool} factory.
3
+ */
4
+ export interface ReadFileToolOptions {
5
+ /**
6
+ * Glob patterns specifying which paths the tool is allowed to read.
7
+ * When provided, only matching paths are accessible.
8
+ */
9
+ allowedPaths?: string[];
10
+ /**
11
+ * Glob patterns specifying which paths the tool must not read.
12
+ * Defaults to node_modules and .env patterns.
13
+ */
14
+ deniedPaths?: string[];
15
+ /**
16
+ * Maximum file size in bytes that the tool will read.
17
+ * Files exceeding this limit cause an error.
18
+ * @defaultValue `1_048_576` (1 MB)
19
+ */
20
+ maxSize?: number;
21
+ /**
22
+ * Base directory against which relative file paths are resolved.
23
+ * @defaultValue `process.cwd()`
24
+ */
25
+ basePath?: string;
26
+ }
27
+ /**
28
+ * Creates a tool definition that reads file contents from the filesystem.
29
+ *
30
+ * The tool enforces path-based security via allow/deny glob patterns and
31
+ * rejects files that exceed the configured size limit.
32
+ *
33
+ * @param options - Optional configuration for path security and size limits.
34
+ * @returns A tool definition compatible with the agentier core runtime.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * import { readFileTool } from '@agentier/tools'
39
+ *
40
+ * const tool = readFileTool({
41
+ * basePath: '/project',
42
+ * maxSize: 512 * 1024,
43
+ * })
44
+ * ```
45
+ */
46
+ export declare function readFileTool(options?: ReadFileToolOptions): import("@agentier/core").Tool<{
47
+ path: string;
48
+ encoding?: "utf-8" | "base64" | undefined;
49
+ }, string>;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Configuration options for the {@link shellTool} factory.
3
+ */
4
+ export interface ShellToolOptions {
5
+ /**
6
+ * Regex patterns specifying which commands the tool is allowed to execute.
7
+ * When provided, only matching commands are permitted.
8
+ */
9
+ allowedCommands?: RegExp[];
10
+ /**
11
+ * Regex patterns specifying which commands the tool must not execute.
12
+ * When omitted, a default deny list blocks destructive operations such as
13
+ * `rm -rf /`, `sudo`, `shutdown`, and `reboot`.
14
+ */
15
+ deniedCommands?: RegExp[];
16
+ /**
17
+ * Maximum time in milliseconds to wait for the command to complete.
18
+ * @defaultValue `30_000` (30 seconds)
19
+ */
20
+ timeout?: number;
21
+ /**
22
+ * Working directory in which the command is executed.
23
+ * @defaultValue `process.cwd()`
24
+ */
25
+ cwd?: string;
26
+ /**
27
+ * Maximum size in bytes for stdout and stderr buffers.
28
+ * @defaultValue `1_048_576` (1 MB)
29
+ */
30
+ maxOutput?: number;
31
+ }
32
+ /**
33
+ * Creates a tool definition that executes shell commands via Node.js
34
+ * `child_process.exec`.
35
+ *
36
+ * Commands are validated against configurable allow/deny regex lists before
37
+ * execution. The parent context's abort signal is forwarded so the child
38
+ * process is killed on cancellation.
39
+ *
40
+ * @param options - Optional configuration for command security, timeouts,
41
+ * working directory, and output limits.
42
+ * @returns A tool definition compatible with the agentier core runtime.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * import { shellTool } from '@agentier/tools'
47
+ *
48
+ * const tool = shellTool({
49
+ * cwd: '/project',
50
+ * timeout: 10_000,
51
+ * deniedCommands: [/rm/, /sudo/],
52
+ * })
53
+ * ```
54
+ */
55
+ export declare function shellTool(options?: ShellToolOptions): import("@agentier/core").Tool<{
56
+ command: string;
57
+ }, {
58
+ stdout: string;
59
+ stderr: string;
60
+ exitCode: number;
61
+ }>;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @module security
3
+ *
4
+ * Utility functions for validating file paths, URLs, and shell commands
5
+ * against configurable allow/deny lists. Used internally by the tool
6
+ * implementations to enforce security boundaries.
7
+ */
8
+ /**
9
+ * Checks whether a file path is permitted given a base directory and
10
+ * optional allow/deny glob patterns.
11
+ *
12
+ * Evaluation order:
13
+ * 1. Path traversal outside `basePath` is always denied.
14
+ * 2. If the path matches any `deniedPaths` pattern it is denied.
15
+ * 3. If `allowedPaths` is provided and non-empty, the path must match at
16
+ * least one pattern.
17
+ * 4. Otherwise the path is allowed.
18
+ *
19
+ * @param filePath - The file path to check (relative or absolute).
20
+ * @param basePath - The root directory all paths are resolved against.
21
+ * @param allowedPaths - Optional glob patterns that explicitly allow access.
22
+ * @param deniedPaths - Optional glob patterns that explicitly deny access.
23
+ * @returns `true` if the path is permitted, `false` otherwise.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * isPathAllowed('src/index.ts', '/project') // true
28
+ * isPathAllowed('../etc/passwd', '/project') // false (traversal)
29
+ * isPathAllowed('.env.local', '/project', undefined,
30
+ * ['.env*']) // false (denied)
31
+ * ```
32
+ */
33
+ export declare function isPathAllowed(filePath: string, basePath: string, allowedPaths?: string[], deniedPaths?: string[]): boolean;
34
+ /**
35
+ * Checks whether a URL is permitted given optional allow/deny regex lists.
36
+ *
37
+ * Evaluation order:
38
+ * 1. If the URL matches any `deniedUrls` pattern it is denied.
39
+ * 2. If `allowedUrls` is provided and non-empty, the URL must match at
40
+ * least one pattern.
41
+ * 3. Otherwise the URL is allowed.
42
+ *
43
+ * @param url - The URL string to validate.
44
+ * @param allowedUrls - Optional regex patterns that explicitly allow access.
45
+ * @param deniedUrls - Optional regex patterns that explicitly deny access.
46
+ * @returns `true` if the URL is permitted, `false` otherwise.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * isUrlAllowed('https://api.example.com/data', [/^https:\/\/api\.example\.com/])
51
+ * // true
52
+ * ```
53
+ */
54
+ export declare function isUrlAllowed(url: string, allowedUrls?: RegExp[], deniedUrls?: RegExp[]): boolean;
55
+ /**
56
+ * Checks whether a shell command is permitted given optional allow/deny
57
+ * regex lists.
58
+ *
59
+ * When no `deniedCommands` list is provided, a sensible default deny list
60
+ * is used that blocks destructive operations such as `rm -rf /`, `sudo`,
61
+ * `shutdown`, and `reboot`.
62
+ *
63
+ * @param command - The shell command string to validate.
64
+ * @param allowedCommands - Optional regex patterns that explicitly allow
65
+ * execution.
66
+ * @param deniedCommands - Optional regex patterns that explicitly deny
67
+ * execution. Overrides the built-in defaults when
68
+ * provided.
69
+ * @returns `true` if the command is permitted, `false` otherwise.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * isCommandAllowed('ls -la') // true
74
+ * isCommandAllowed('sudo rm -rf /') // false (matches default deny list)
75
+ * ```
76
+ */
77
+ export declare function isCommandAllowed(command: string, allowedCommands?: RegExp[], deniedCommands?: RegExp[]): boolean;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Configuration options for the {@link writeFileTool} factory.
3
+ */
4
+ export interface WriteFileToolOptions {
5
+ /**
6
+ * Glob patterns specifying which paths the tool is allowed to write to.
7
+ * When provided, only matching paths are accessible.
8
+ */
9
+ allowedPaths?: string[];
10
+ /**
11
+ * Glob patterns specifying which paths the tool must not write to.
12
+ * Defaults to node_modules and .env patterns.
13
+ */
14
+ deniedPaths?: string[];
15
+ /**
16
+ * Whether to automatically create parent directories if they do not exist.
17
+ * @defaultValue `true`
18
+ */
19
+ createDirs?: boolean;
20
+ /**
21
+ * Base directory against which relative file paths are resolved.
22
+ * @defaultValue `process.cwd()`
23
+ */
24
+ basePath?: string;
25
+ }
26
+ /**
27
+ * Creates a tool definition that writes content to a file on the filesystem.
28
+ *
29
+ * The tool enforces path-based security via allow/deny glob patterns and
30
+ * can optionally create intermediate directories.
31
+ *
32
+ * @param options - Optional configuration for path security and directory
33
+ * creation.
34
+ * @returns A tool definition compatible with the agentier core runtime.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * import { writeFileTool } from '@agentier/tools'
39
+ *
40
+ * const tool = writeFileTool({
41
+ * basePath: '/project',
42
+ * createDirs: true,
43
+ * })
44
+ * ```
45
+ */
46
+ export declare function writeFileTool(options?: WriteFileToolOptions): import("@agentier/core").Tool<{
47
+ path: string;
48
+ content: string;
49
+ }, string>;
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@agentier/tools",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "types": "./dist/index.d.ts"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "scripts": {
17
+ "build": "bun build ./src/index.ts --outdir ./dist --target node",
18
+ "test": "bun test",
19
+ "typecheck": "tsc --noEmit"
20
+ },
21
+ "peerDependencies": {
22
+ "@agentier/core": "^0.1.0"
23
+ },
24
+ "dependencies": {
25
+ "zod": "^3.23.0"
26
+ },
27
+ "devDependencies": {
28
+ "@agentier/core": "workspace:*",
29
+ "typescript": "^5.5.0",
30
+ "@types/bun": "latest"
31
+ }
32
+ }