UNPKG

@bestdefense/bd-agent

Version:

An AI-powered coding assistant CLI that connects to AWS Bedrock

169 lines 5.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.gitTools = void 0; const child_process_1 = require("child_process"); const util_1 = require("util"); const execAsync = (0, util_1.promisify)(child_process_1.exec); exports.gitTools = [ { name: 'git_status', description: 'Get the current git status', input_schema: { type: 'object', properties: { path: { type: 'string', description: 'The repository path (optional, defaults to current directory)' } } }, execute: async ({ path }) => { try { const cwd = path || process.cwd(); const { stdout, stderr } = await execAsync('git status --porcelain', { cwd }); if (stderr) { return { success: false, error: stderr }; } const changes = stdout.split('\n').filter(line => line.trim()); return { success: true, changes: changes.length > 0 ? changes : 'No changes detected', count: changes.length }; } catch (error) { return { success: false, error: error.message }; } } }, { name: 'git_diff', description: 'Show git diff for staged or unstaged changes', input_schema: { type: 'object', properties: { staged: { type: 'boolean', description: 'Show staged changes (default: false)' }, path: { type: 'string', description: 'The repository path (optional)' } } }, execute: async ({ staged, path }) => { try { const cwd = path || process.cwd(); const command = staged ? 'git diff --cached' : 'git diff'; const { stdout, stderr } = await execAsync(command, { cwd }); if (stderr) { return { success: false, error: stderr }; } return { success: true, diff: stdout || 'No differences found' }; } catch (error) { return { success: false, error: error.message }; } } }, { name: 'git_add', description: 'Stage files for commit', input_schema: { type: 'object', properties: { files: { type: 'array', items: { type: 'string' }, description: 'Files to stage (use ["."] for all files)' }, path: { type: 'string', description: 'The repository path (optional)' } }, required: ['files'] }, execute: async ({ files, path }) => { try { const cwd = path || process.cwd(); const filesStr = files.join(' '); const { stdout, stderr } = await execAsync(`git add ${filesStr}`, { cwd }); if (stderr) { return { success: false, error: stderr }; } return { success: true, message: `Files staged: ${filesStr}` }; } catch (error) { return { success: false, error: error.message }; } } }, { name: 'git_commit', description: 'Create a git commit', input_schema: { type: 'object', properties: { message: { type: 'string', description: 'Commit message' }, path: { type: 'string', description: 'The repository path (optional)' } }, required: ['message'] }, execute: async ({ message, path }) => { try { const cwd = path || process.cwd(); const { stdout, stderr } = await execAsync(`git commit -m "${message}"`, { cwd }); if (stderr && !stderr.includes('files changed')) { return { success: false, error: stderr }; } return { success: true, output: stdout }; } catch (error) { return { success: false, error: error.message }; } } }, { name: 'git_log', description: 'Show recent git commits', input_schema: { type: 'object', properties: { limit: { type: 'number', description: 'Number of commits to show (default: 10)' }, path: { type: 'string', description: 'The repository path (optional)' } } }, execute: async ({ limit = 10, path }) => { try { const cwd = path || process.cwd(); const { stdout, stderr } = await execAsync(`git log --oneline -n ${limit}`, { cwd }); if (stderr) { return { success: false, error: stderr }; } const commits = stdout.split('\n').filter(line => line.trim()); return { success: true, commits }; } catch (error) { return { success: false, error: error.message }; } } } ]; //# sourceMappingURL=git.js.map