@webdevtoday/grok-cli
Version:
A sophisticated CLI tool for interacting with xAI Grok 4, featuring conversation history, file reference, custom commands, memory system, and genetic development workflows
140 lines • 4.85 kB
JavaScript
;
/**
* Bash command execution tool
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.BashTool = void 0;
const base_1 = require("./base");
const execa_1 = require("execa");
/**
* Tool for executing bash commands
*/
class BashTool extends base_1.BaseTool {
constructor() {
super('Bash', 'Execute command line tools for genetic development (git, uv, python, npm, mysql, postgres, docker, tmux, etc.) - supports multi-agent environments');
}
validateParams(params) {
return (typeof params['command'] === 'string' &&
params['command'].length > 0 &&
(params['timeout'] === undefined || typeof params['timeout'] === 'number') &&
(params['cwd'] === undefined || typeof params['cwd'] === 'string') &&
(params['env'] === undefined || typeof params['env'] === 'object'));
}
async execute(params) {
const { command, timeout = 30000, cwd, env } = params;
try {
const result = await (0, execa_1.execa)('bash', ['-c', command], {
timeout,
cwd: cwd || process.cwd(),
env: { ...process.env, ...env },
reject: false, // Don't throw on non-zero exit codes
});
const success = result.exitCode === 0;
const output = result.stdout || '';
const error = result.stderr || undefined;
return {
success,
output,
error: error || undefined,
metadata: {
command,
exitCode: result.exitCode,
duration: result.durationMs || 0,
cwd: cwd || process.cwd(),
},
};
}
catch (error) {
return {
success: false,
output: '',
error: error instanceof Error ? error.message : String(error),
metadata: {
command,
cwd: cwd || process.cwd(),
},
};
}
}
getParameterSchema() {
return {
type: 'object',
properties: {
command: {
type: 'string',
description: 'The command to execute (e.g., git status, python --version, npm install, mysql --version, psql -l, tmux new-session)',
},
timeout: {
type: 'number',
description: 'Timeout in milliseconds (default: 30000)',
default: 30000,
},
cwd: {
type: 'string',
description: 'Working directory for command execution',
},
env: {
type: 'object',
description: 'Environment variables for command execution',
},
},
required: ['command'],
};
}
getUsageExamples() {
return [
// Basic system commands
'ls -la',
'pwd',
'whoami',
'which python',
// Git commands
'git status',
'git log --oneline -10',
'git branch -a',
'git diff',
// Python/UV commands
'python --version',
'python -m pip list',
'uv --version',
'uv pip install requests',
'uv run python script.py',
// Node.js/npm commands
'npm --version',
'npm install',
'npm run build',
'npm test',
'node --version',
// Package managers
'brew --version',
'apt list --installed',
'yum list installed',
// Database commands
'mysql --version',
'mysql -u root -p -e "SHOW DATABASES;"',
'psql --version',
'psql -U postgres -l',
'sqlite3 --version',
'redis-cli --version',
'mongosh --version',
// Multi-agent & session management
'tmux --version',
'tmux list-sessions',
'tmux new-session -d -s agent1',
'tmux send-keys -t agent1 "echo Hello from agent1" Enter',
'screen --version',
// Development tools
'docker --version',
'kubectl version --client',
'terraform --version',
'curl -s https://api.github.com/users/octocat',
// Genetic development workflows
'make --version',
'cmake --version',
'gcc --version',
'clang --version',
];
}
}
exports.BashTool = BashTool;
//# sourceMappingURL=bash.js.map