cline-sdk
Version:
Comprehensive SDK for Cline - AI-powered development assistant with database integration, execution modes, and custom functions
80 lines • 2.64 kB
JavaScript
;
/**
* Bash Tool - Execute shell commands
* Based on VSCode extension's bashTool implementation
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.BashTool = void 0;
const child_process_1 = require("child_process");
class BashTool {
constructor(workingDirectory) {
this.workingDirectory = workingDirectory;
}
async execute(input) {
const { command } = input;
return new Promise((resolve) => {
const shell = process.platform === "win32" ? "cmd" : "bash";
const args = process.platform === "win32" ? ["/c", command] : ["-c", command];
const child = (0, child_process_1.spawn)(shell, args, {
cwd: this.workingDirectory,
stdio: ["pipe", "pipe", "pipe"],
env: { ...process.env },
});
let stdout = "";
let stderr = "";
child.stdout?.on("data", (data) => {
stdout += data.toString();
});
child.stderr?.on("data", (data) => {
stderr += data.toString();
});
child.on("close", (code) => {
resolve({
success: code === 0,
stdout: stdout.trim(),
stderr: stderr.trim(),
exit_code: code || 0,
command,
});
});
child.on("error", (error) => {
resolve({
success: false,
stdout: "",
stderr: error.message,
exit_code: 1,
command,
});
});
// Set timeout
setTimeout(() => {
child.kill();
resolve({
success: false,
stdout,
stderr: stderr + "\nCommand timed out after 30 seconds",
exit_code: 124,
command,
});
}, 30000);
});
}
getDefinition() {
return {
name: "Bash",
description: "Execute shell commands in the working directory",
inputSchema: {
type: "object",
properties: {
command: {
type: "string",
description: "The shell command to execute",
},
},
required: ["command"],
},
};
}
}
exports.BashTool = BashTool;
//# sourceMappingURL=bash-tool.js.map