UNPKG

giga-code

Version:

A personal AI CLI assistant powered by Grok for local development.

81 lines 3.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BashTool = void 0; const child_process_1 = require("child_process"); const util_1 = require("util"); const confirmation_service_1 = require("../utils/confirmation-service"); const execAsync = (0, util_1.promisify)(child_process_1.exec); class BashTool { constructor() { this.currentDirectory = process.cwd(); this.confirmationService = confirmation_service_1.ConfirmationService.getInstance(); } async execute(command, timeout = 30000) { try { // Check if user has already accepted bash commands for this session const sessionFlags = this.confirmationService.getSessionFlags(); if (!sessionFlags.bashCommands && !sessionFlags.allOperations) { // Request confirmation showing the command const confirmationResult = await this.confirmationService.requestConfirmation({ operation: 'Run bash command', filename: command, showVSCodeOpen: false, content: `Command: ${command}\nWorking directory: ${this.currentDirectory}` }, 'bash'); if (!confirmationResult.confirmed) { return { success: false, error: confirmationResult.feedback || 'Command execution cancelled by user' }; } } if (command.startsWith('cd ')) { const newDir = command.substring(3).trim(); try { process.chdir(newDir); this.currentDirectory = process.cwd(); return { success: true, output: `Changed directory to: ${this.currentDirectory}` }; } catch (error) { return { success: false, error: `Cannot change directory: ${error.message}` }; } } const { stdout, stderr } = await execAsync(command, { cwd: this.currentDirectory, timeout, maxBuffer: 1024 * 1024 }); const output = stdout + (stderr ? `\nSTDERR: ${stderr}` : ''); return { success: true, output: output.trim() || 'Command executed successfully (no output)' }; } catch (error) { return { success: false, error: `Command failed: ${error.message}` }; } } getCurrentDirectory() { return this.currentDirectory; } async listFiles(directory = '.') { return this.execute(`ls -la ${directory}`); } async findFiles(pattern, directory = '.') { return this.execute(`find ${directory} -name "${pattern}" -type f`); } async grep(pattern, files = '.') { return this.execute(`grep -r "${pattern}" ${files}`); } } exports.BashTool = BashTool; //# sourceMappingURL=bash.js.map