@bestdefense/bd-agent
Version:
An AI-powered coding assistant CLI that connects to AWS Bedrock
180 lines • 6.56 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.fileSystemTools = void 0;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const util_1 = require("util");
const readFile = (0, util_1.promisify)(fs.readFile);
const writeFile = (0, util_1.promisify)(fs.writeFile);
const readdir = (0, util_1.promisify)(fs.readdir);
const stat = (0, util_1.promisify)(fs.stat);
exports.fileSystemTools = [
{
name: 'read_file',
description: 'Read the contents of a file',
input_schema: {
type: 'object',
properties: {
path: {
type: 'string',
description: 'The file path to read'
}
},
required: ['path']
},
execute: async ({ path: filePath }) => {
try {
const absolutePath = path.resolve(filePath);
const content = await readFile(absolutePath, 'utf-8');
return { success: true, content };
}
catch (error) {
return { success: false, error: error.message };
}
}
},
{
name: 'write_file',
description: 'Write content to a file',
input_schema: {
type: 'object',
properties: {
path: {
type: 'string',
description: 'The file path to write'
},
content: {
type: 'string',
description: 'The content to write'
}
},
required: ['path', 'content']
},
execute: async ({ path: filePath, content }) => {
try {
const absolutePath = path.resolve(filePath);
const dir = path.dirname(absolutePath);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
await writeFile(absolutePath, content, 'utf-8');
return { success: true, message: `File written to ${absolutePath}` };
}
catch (error) {
return { success: false, error: error.message };
}
}
},
{
name: 'edit_file',
description: 'Edit a file by replacing content',
input_schema: {
type: 'object',
properties: {
path: {
type: 'string',
description: 'The file path to edit'
},
old_content: {
type: 'string',
description: 'The content to replace'
},
new_content: {
type: 'string',
description: 'The new content'
}
},
required: ['path', 'old_content', 'new_content']
},
execute: async ({ path: filePath, old_content, new_content }) => {
try {
const absolutePath = path.resolve(filePath);
const content = await readFile(absolutePath, 'utf-8');
if (!content.includes(old_content)) {
return { success: false, error: 'Old content not found in file' };
}
const updatedContent = content.replace(old_content, new_content);
await writeFile(absolutePath, updatedContent, 'utf-8');
return {
success: true,
message: 'File edited successfully',
diff: {
old: old_content,
new: new_content
}
};
}
catch (error) {
return { success: false, error: error.message };
}
}
},
{
name: 'list_directory',
description: 'List files and directories in a path',
input_schema: {
type: 'object',
properties: {
path: {
type: 'string',
description: 'The directory path to list'
}
},
required: ['path']
},
execute: async ({ path: dirPath }) => {
try {
const absolutePath = path.resolve(dirPath || '.');
const items = await readdir(absolutePath);
const details = await Promise.all(items.map(async (item) => {
const itemPath = path.join(absolutePath, item);
const stats = await stat(itemPath);
return {
name: item,
type: stats.isDirectory() ? 'directory' : 'file',
size: stats.size,
modified: stats.mtime
};
}));
return { success: true, items: details };
}
catch (error) {
return { success: false, error: error.message };
}
}
}
];
//# sourceMappingURL=file-system.js.map