Overview
The Tools module provides core tool implementations for file operations, shell execution, web fetching, web search, and agent-to-agent communication. All tools include automatic metrics collection and security enforcement.
File Operations
Read file contents with path containment security checks.
File path relative to WORKSPACE_ROOT
Optional maximum bytes to read (for limiting large files)
The file contents (limited by maxBytes if specified)
The resolved absolute path
The total file size in bytes
const result = await trigger ( 'tool::file_read' , {
path: 'src/config.ts' ,
maxBytes: 10000
});
console . log ( `Read ${ result . content . length } of ${ result . size } bytes` );
Security : Automatically enforces path containment via assertPathContained() to prevent directory traversal attacks.
Write content to a file with path containment security.
File path relative to WORKSPACE_ROOT
Content to write to the file
Confirmation of successful write
The resolved absolute path
The number of bytes written
const result = await trigger ( 'tool::file_write' , {
path: 'output/result.json' ,
content: JSON . stringify ({ status: 'success' }, null , 2 )
});
console . log ( `Wrote ${ result . size } bytes to ${ result . path } ` );
List directory contents with file metadata.
Directory path relative to WORKSPACE_ROOT
Whether to recursively list subdirectories (not fully implemented)
The resolved directory path
Array of file/directory entries with:
name (string): Entry name
type (“file” | “directory”): Entry type
size (number): Size in bytes
modified (string): ISO timestamp of last modification
const result = await trigger ( 'tool::file_list' , {
path: 'src'
});
result . entries . forEach ( entry => {
console . log ( ` ${ entry . type } : ${ entry . name } ( ${ entry . size } bytes)` );
});
Apply a unified diff patch to a file.
File path to apply the patch to
Unified diff format patch content
Confirmation of successful patch application
const patch = `@@ -1,3 +1,3 @@
-const version = "1.0.0";
+const version = "1.1.0";
` ;
const result = await trigger ( 'tool::apply_patch' , {
path: 'src/version.ts' ,
patch
});
Shell Execution
Execute commands with sandboxing and allowlist enforcement. No shell interpretation - direct binary execution only.
Command array [binary, …args] - first element must be in SHELL_COMMAND_ALLOWLIST
Working directory relative to WORKSPACE_ROOT
Execution timeout in milliseconds (default: 120000)
Standard output (limited to 100KB)
Standard error output (limited to 50KB)
Process exit code (0 = success)
Allowed Commands
const SHELL_COMMAND_ALLOWLIST = [
'git' , 'node' , 'npm' , 'npx' , 'bun' , 'deno' ,
'python3' , 'python' , 'pip' ,
'ls' , 'cat' , 'grep' , 'find' , 'echo' , 'mkdir' , 'touch' , 'cp' , 'mv' ,
'head' , 'tail' , 'wc' , 'sort' , 'uniq' , 'diff' ,
'curl' , 'wget' , 'tar' , 'zip' , 'unzip' , 'jq' , 'sed' , 'awk' ,
'which' , 'env' , 'date' ,
'cargo' , 'rustc' , 'go' , 'make' , 'cmake'
];
Run Git Command
Run NPM Install
const result = await trigger ( 'tool::shell_exec' , {
argv: [ 'git' , 'status' , '--short' ],
cwd: 'my-project'
});
if ( result . exitCode === 0 ) {
console . log ( 'Git status:' , result . stdout );
} else {
console . error ( 'Error:' , result . stderr );
}
Security :
Only allowlisted binaries can be executed
No shell interpretation (prevents injection)
Environment variables filtered through TAINT_ENV_ALLOWLIST
Path containment enforced on working directory
Output size limits prevent memory exhaustion
Execution logged to security audit
Web Access
SSRF-protected HTTP fetch with automatic HTML-to-text conversion.
URL to fetch (validated against SSRF attacks)
Maximum response size in bytes (default: 500000)
Response content type header
Response content (HTML converted to text, limited to 100KB)
Whether content was truncated due to size limits
const result = await trigger ( 'tool::web_fetch' , {
url: 'https://example.com/docs' ,
maxSize: 100000
});
if ( result . status === 200 ) {
console . log ( 'Content:' , result . content . slice ( 0 , 500 ));
}
Security : Automatically calls assertNoSsrf() to prevent requests to internal IP ranges.
Multi-provider web search supporting Tavily, Brave, and DuckDuckGo.
Search provider: “tavily”, “brave”, or fallback to “duckduckgo”
Maximum number of results (default: 5)
Array of search results with title, url, and content fields
The provider that served the results
const result = await trigger ( 'tool::web_search' , {
query: 'TypeScript async patterns' ,
provider: 'brave' ,
maxResults: 10
});
result . results . forEach ( item => {
console . log ( ` ${ item . title } : ${ item . url } ` );
});
Provider Configuration :
Tavily : Requires TAVILY_API_KEY environment variable
Brave : Requires BRAVE_API_KEY environment variable
DuckDuckGo : No API key required (default fallback)
Agent Communication
Spawn a sub-agent with depth limits and resource quotas.
Template identifier for the sub-agent type
Parent agent ID for tracking hierarchy
Initial message to send to the spawned agent
The newly created agent’s ID
The agent’s response content
Depth level in the agent hierarchy
Limits :
MAX_AGENT_DEPTH : 5 - Maximum nesting depth
DEFAULT_MAX_SUB_AGENTS : 20 - Default quota per parent
const result = await trigger ( 'tool::agent_spawn' , {
template: 'code-analyzer' ,
parentId: 'agent-123' ,
message: 'Analyze the TypeScript files in src/'
});
console . log ( `Spawned agent ${ result . agentId } at depth ${ result . depth } ` );
console . log ( 'Response:' , result . response );
Send a message to another agent with spam prevention.
Message content (max 100KB)
Confirmation of message queuing
Rate Limits :
MESSAGE_MAX_BYTES : 100KB - Maximum message size
MESSAGE_QUEUE_MAX : 1000 - Maximum queue depth per agent
AGENT_PAIR_RATE_LIMIT : 10 messages per minute between any agent pair
const result = await trigger ( 'tool::agent_send' , {
agentId: 'agent-123' ,
targetAgentId: 'agent-456' ,
message: 'Task completed, ready for next step'
});
if ( result . sent ) {
console . log ( 'Message queued successfully' );
}
Metrics Wrapper
All tools automatically use the withToolMetrics() wrapper which records:
tool_execution_total - Execution count by status (success/failure)
function_call_duration_ms - Execution duration histogram
Location : tools.ts:27