nohandcoder
Version:
An AI agent for code editing, searching, and project analysis
52 lines (51 loc) • 1.9 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EditFileTool = void 0;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const chalk_1 = __importDefault(require("chalk"));
class EditFileTool {
constructor(workspaceRoot) {
this.workspaceRoot = workspaceRoot;
}
getDefinition() {
return {
type: "function",
function: {
name: "editFile",
description: "Edit the contents of a file",
parameters: {
type: "object",
properties: {
filePath: {
type: "string",
description: "Path to the file to edit (relative to current directory)",
},
content: {
type: "string",
description: "The new content to write to the file",
},
},
required: ["filePath", "content"],
additionalProperties: false,
},
strict: true,
},
};
}
async execute(args) {
console.log(chalk_1.default.blue("\nEditing file...", args.filePath));
const fullPath = path_1.default.isAbsolute(args.filePath)
? args.filePath
: path_1.default.join(this.workspaceRoot, args.filePath);
await fs_1.default.promises.writeFile(fullPath, args.content, "utf-8");
return {
success: true,
message: `File ${args.filePath} updated successfully`,
};
}
}
exports.EditFileTool = EditFileTool;
;