nohandcoder
Version:
An AI agent for code editing, searching, and project analysis
59 lines (58 loc) • 1.92 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExecuteCommandTool = void 0;
const child_process_1 = require("child_process");
const util_1 = require("util");
const chalk_1 = __importDefault(require("chalk"));
const execAsync = (0, util_1.promisify)(child_process_1.exec);
class ExecuteCommandTool {
constructor(workspaceRoot) {
this.workspaceRoot = workspaceRoot;
}
getDefinition() {
return {
type: "function",
function: {
name: "executeCommand",
description: "Execute a shell command",
parameters: {
type: "object",
properties: {
command: {
type: "string",
description: "Command to execute",
},
},
required: ["command"],
additionalProperties: false,
},
strict: true,
},
};
}
async execute(args) {
console.log(chalk_1.default.blue("\nExecuting command...", args.command));
try {
const command = args.command;
const { stdout, stderr } = await execAsync(command, {
cwd: this.workspaceRoot,
});
return {
success: true,
output: stdout,
error: stderr,
};
}
catch (error) {
return {
success: false,
output: "",
error: error instanceof Error ? error.message : "Unknown error occurred",
};
}
}
}
exports.ExecuteCommandTool = ExecuteCommandTool;
;