hataraku
Version:
An autonomous coding agent for building AI-powered development tools. The name "Hataraku" (働く) means "to work" in Japanese.
79 lines • 3.31 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createExecuteCommandTool = createExecuteCommandTool;
const zod_1 = require("zod");
const child_process_1 = require("child_process");
const chalk_1 = __importDefault(require("chalk"));
function createExecuteCommandTool(config = {}) {
return {
description: "Execute a CLI command on the system. Commands will be executed in the current working directory.",
parameters: zod_1.z.object({
command: zod_1.z.string().describe('The CLI command to execute. This should be valid for the current operating system.')
}),
execute: async ({ command }) => {
return new Promise((resolve) => {
const childProcess = (0, child_process_1.spawn)(command, [], {
shell: true,
cwd: process.cwd()
});
let output = '';
let error = '';
const colorFn = config.outputColor ? chalk_1.default[config.outputColor] : undefined;
childProcess.stdout.on('data', (data) => {
const text = data.toString();
output += text;
// Log output in real-time with configured color
if (colorFn) {
process.stdout.write(colorFn(text));
}
else {
console.log(text);
}
});
childProcess.stderr.on('data', (data) => {
const text = data.toString();
error += text;
// Log errors in real-time with configured color
if (colorFn) {
process.stderr.write(colorFn(text));
}
else {
console.error(text);
}
});
childProcess.on('close', (code) => {
if (code !== 0) {
resolve({
isError: true,
content: [{
type: "text",
text: error || `Command failed with code ${code}`
}]
});
}
else {
resolve({
content: [{
type: "text",
text: output || 'Command completed successfully with no output'
}]
});
}
});
childProcess.on('error', (err) => {
resolve({
isError: true,
content: [{
type: "text",
text: `Failed to execute command: ${err.message}`
}]
});
});
});
}
};
}
//# sourceMappingURL=execute-command.js.map